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(); }
internal FtpDataConnection Execute(int timeout) { if (_passiveMode) { FtpResponse response = _cc.SendCommandEx(timeout, "PASV"); if (false == response.IsCompletionReply) { NSTrace.WriteLineError("PASV: " + response.ToString()); throw new FtpErrorException("Error while configuring data connection.", response); } IPEndPoint ep = GetPasvEndPoint(response); return(new FtpDataConnectionOutbound(_client, ep)); } else { IPEndPoint ep = GetLocalEndPoint(); FtpDataConnectionInbound dconn = new FtpDataConnectionInbound(_client, ep); //prepare data connection dconn.Prepare(timeout, _cc.UsedSocket); //get the inbound data connection attributes string cmd = GetPortCmd(dconn.LocalEndPoint); //send tranfser parameters to the server FtpResponse response = _cc.SendCommandEx(timeout, cmd); if (false == response.IsCompletionReply) { dconn.Dispose(); NSTrace.WriteLineError(cmd + ": " + response.ToString()); throw new FtpErrorException("Error while configuring data connection.", response); } return(dconn); } }