internal IAsyncResult BeginExecute(int timeout, AsyncCallback cb, object state) { SetProgress(true); GetDC_SO stateObj = null; try { stateObj = new GetDC_SO(timeout, cb, state); if (_passiveMode) { _cc.BeginSendCommandEx(timeout, "PASV", new AsyncCallback(this.GetDC_EndCmd), stateObj); } else { IPEndPoint ep = GetLocalEndPoint(); stateObj.DC = new FtpDataConnectionInbound(_client, ep); stateObj.DC.BeginPrepare(timeout, _cc.UsedSocket, new AsyncCallback(Prepare_End), stateObj); } } finally { SetProgress(false); } return(stateObj); }
internal FtpDataConnection EndExecute(IAsyncResult ar) { AsyncBase.VerifyAsyncResult(ar, typeof(GetDC_SO)); HandleAsyncEnd(ar, true); GetDC_SO stateObj = (GetDC_SO)ar; return(stateObj.DC); }
void Prepare_End(IAsyncResult ar) { GetDC_SO stateObj = (GetDC_SO)ar.AsyncState; try { stateObj.UpdateContext(); stateObj.DC.EndPreapre(ar); stateObj.Cmd = GetPortCmd(stateObj.DC.LocalEndPoint); _cc.BeginSendCommandEx(stateObj.Timeout, stateObj.Cmd, new AsyncCallback(this.GetDC_EndCmd), stateObj); } catch (Exception e) { stateObj.Exception = e; stateObj.SetCompleted(); } }
void GetDC_EndCmd(IAsyncResult ar) { GetDC_SO stateObj = (GetDC_SO)ar.AsyncState; try { stateObj.UpdateContext(); FtpResponse response = _cc.EndSendCommandEx(ar); if (_passiveMode) { if (false == response.IsCompletionReply) { NSTrace.WriteLineError("PASV: " + response.ToString()); stateObj.Exception = new FtpErrorException("Error while configuring data connection.", response); } else { IPEndPoint ep = GetPasvEndPoint(response); stateObj.DC = new FtpDataConnectionOutbound(_client, ep); } } else { if (false == response.IsCompletionReply) { stateObj.DC.Dispose(); stateObj.DC = null; NSTrace.WriteLineError(stateObj.Cmd + ": " + response.ToString()); stateObj.Exception = new FtpErrorException("Error while configure data connection.", response); } } } catch (Exception e) { stateObj.Exception = e; } stateObj.SetCompleted(); }