Exemplo n.º 1
0
        public bool FTP_Init(string ipAddress, int port)
        {
            if (ftpClient != null && ftpClient.IsConnected())
            {
                ftpClient.Close();
            }
            ftpClient = new FtpClientManager(ipAddress, port, "ftp_cli");
                //AppendConsoleMsg("[SERVER_CONNECT]Socket Already Inited.");

            ftpClient.SocStatusChanged += SocStatusChanged;

            if (!ftpClient.IsConnected())
            {
                if (ftpClient.Connect())
                    AppendConsoleMsg(">[SERVER_CONNECT]Server Connected.");
                else
                {
                    AppendConsoleMsg(">[SERVER_CONNECT]Server Not Connected.");
                    return false;
                }
            }
            else
                AppendConsoleMsg(">[SERVER_CONNECT]Server Already Connected.");

            string file = Utils.GetFileName(mFullFileName);
            string path = Utils.GetPath(mFullFileName);

            ftpClient.setFileName(file);
            ftpClient.setFilePath(path);
            return true;
        }
Exemplo n.º 2
0
        public void FILE_TCPSend(string fileName, string formKey, string rcvId, IPEndPoint iep) 
        {
            mRcvId = rcvId;
            logWrite("FILE_TCPSend: 파일전송 포트 변경 :" + SocketDef.PORT_FILE_NEW_SERVER);

            FileInfo fi = new FileInfo(fileName);
            logWrite("FILE_TCPSend: FileInfo 인스턴스 생성 : " + fileName);

            showFileSendDetailDelegate = new ShowFileSendDetailDelegate(ShowFileSendDetail);
            showFileSendStatDelegate = new ShowFileSendStatDelegate(ShowFileSendStat);
            showFileSendStatExDelegate = new ShowFileSendStatExDelegate(ShowFileSendStatEx);
            showCloseButtonDelegate = new ShowCloseButtonDelegate(ShowCloseButton);
            
            SendFileForm sendFileForm = (SendFileForm)FileSendFormList[formKey];
            FileSendDetailListView fileSendDetailList = (FileSendDetailListView)FileSendDetailList[formKey];

            if (!fi.Exists)
            {
                logWrite("SendFile() 파일이 없음 : " + fileName);
                return;
            }

            FtpClientManager ftpClient = new FtpClientManager(iep.Address.ToString(), SocketDef.PORT_FILE_NEW_SERVER, formKey);
            FtpClientThreadList[formKey] = ftpClient;
            ftpClient.SocStatusChanged += FTP_SndStatusChanged;

            if (!ftpClient.IsConnected())
            {
                if (ftpClient.Connect())
                    logWrite("[FILE_TCPSend]Server Connected.");
                else
                {
                    logWrite("[FILE_TCPSend]Server Not Connected.");
                    MessageBox.Show("파일전송 실패 : 상대방이 응답하지 않음", "전송실패", MessageBoxButtons.OK);
                    if (FileSendFormList.Count != 0 && FileSendFormList[formKey] != null)
                    {
                        //CHOI_DEBUG Invoke(showFileSendStatDelegate, new object[] { "전송실패", -1, sendFileForm });
                        Invoke(showFileSendStatExDelegate, new object[] { DownloadStatus.FAILED, "전송실패", -1, sendFileForm });
                    }
                    return;
                }
            }
            else
                logWrite("[FILE_TCPSend]Server Already Connected.");

            string file = Utils.GetFileName(fileName);
            string path = Utils.GetPath(fileName);

            ftpClient.setFileName(file);
            ftpClient.setFilePath(path);

            try
            {
                if (ftpClient.SendFile())
                {
                    string detailmsg = "전송완료";
                    if (iep.Address.ToString().Equals(serverIP))
                    {
                        Invoke(showFileSendDetailDelegate, new object[] { "server", detailmsg, fileSendDetailList });
                    }
                    else
                    {
                        Invoke(showFileSendDetailDelegate, new object[] { rcvId, detailmsg, fileSendDetailList });
                    }
                    bool isFinished = (bool)Invoke(showCloseButtonDelegate, fileSendDetailList);  //자세히
                    if (isFinished == false)
                        //CHOI_DEBUG Invoke(showFileSendStatDelegate, new object[] { detailmsg, 100, sendFileForm });  //FileSendForm
                        Invoke(showFileSendStatExDelegate, new object[] { DownloadStatus.SUCCESS, detailmsg, 100, sendFileForm });  //FileSendForm
                    else
                        //CHOI_DEBUG Invoke(showFileSendStatDelegate, new object[] { "Finish", 100, sendFileForm });  //FileSendForm
                        Invoke(showFileSendStatExDelegate, new object[] { DownloadStatus.SUCCESS, "Finish", 100, sendFileForm });  //FileSendForm
                }
                else
                {
                    logWrite("[FILE_TCPSend]Server Not Connected.");
                    MessageBox.Show("파일전송 실패 : 상대방이 응답하지 않음", "전송실패", MessageBoxButtons.OK);
                    if (FileSendFormList.Count != 0 && FileSendFormList[formKey] != null)
                    {
                        Invoke(showFileSendStatExDelegate, new object[] { DownloadStatus.FAILED, "전송실패", -1, sendFileForm });
                        //CHOI_DEBUG Invoke(showFileSendStatDelegate, new object[] { "전송실패", -1, sendFileForm });
                    }

                    ftpClient.Close();
                }
            }
            catch (IOException)
            {
            }
            finally
            {

            }
            try
            {
                if (FileSendThreadList.Count != 0 && FileSendThreadList[formKey + "|" + rcvId] != null)
                {
                    ((Thread)FileSendThreadList[formKey + "|" + rcvId]).Abort();
                    logWrite("FileSendThread Abort()!");
                }
            }
            catch (ThreadAbortException te)
            {
                logWrite(te.ToString());
            }
        }