Пример #1
0
        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();
            }
        }
Пример #2
0
        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();
        }