/// <summary> /// 数据传输完毕的回调函数 /// </summary> /// <param name="byteTransfered"></param> /// <param name="timeElapsed"></param> /// <param name="_dataAsyncSocket"></param> public void TransferCommpleted(int byteTransfered, int timeElapsed,DataAsyncSocket _dataAsyncSocket ) { string s; if (_dataAsyncSocket == null) { s = String.Empty; } else { s = _dataAsyncSocket.Response; _dataAsyncSocket.DisConnect(); } FtpEventArgs e = new FtpEventArgs(); e.Totalbytes = byteTransfered; e.Timeelapsed = timeElapsed; e.SMessage = s; e.Workid = _dataAsyncSocket.Workid; if (_dataAsyncSocket.CmdData == 0) _ftpHelper.OnDirCommpleted(e); else if (_dataAsyncSocket.CmdData == 1) _ftpHelper.OnFileDownLoadCommpleted(e); else _ftpHelper.OnFileUpLoadCommpleted(e); _dataAsyncSocket = null; }
/// <summary> /// 根据下一跳命令,创建list、上传、下载3中不同的功能的DATASocket /// </summary> /// <param name="ipAddress"></param> /// <param name="port"></param> private void CreateDataSocket(string ipAddress, int port) { string workid = ""; DataAsyncSocket _dataAsyncSocket = new DataAsyncSocket(this); if (_nextCommand.Command == "LIST") { _dataAsyncSocket.CmdData = 0; } else { workid = _nextCommand.WorkId; if (_ftpHelper.Localfolder.EndsWith("\\")) { _dataAsyncSocket.FileName = _ftpHelper.Localfolder + _nextCommand.SParam; } else { _dataAsyncSocket.FileName = _ftpHelper.Localfolder + "\\" + _nextCommand.SParam; } if (_nextCommand.Command == "RETR") { _dataAsyncSocket.FileSize = _nextCommand.IParam; _dataAsyncSocket.CmdData = 1; } else if(_nextCommand.Command=="STOR") { _dataAsyncSocket.FileSize = _nextCommand.IParam; _dataAsyncSocket.CmdData = 2; } } //启动链接等待传输 _dataAsyncSocket.Connect(ipAddress, port,workid ); }