private CommandStream.PipelineInstruction QueueOrCreateFtpDataStream(ref Stream stream)
        {
            if (this.m_DataSocket == null)
            {
                throw new InternalException();
            }
            if (this.m_TlsStream != null)
            {
                stream           = new FtpDataStream(this.m_TlsStream, (FtpWebRequest)base.m_Request, this.IsFtpDataStreamWriteable());
                this.m_TlsStream = null;
                return(CommandStream.PipelineInstruction.GiveStream);
            }
            NetworkStream networkStream = new NetworkStream(this.m_DataSocket, true);

            if (base.UsingSecureStream)
            {
                FtpWebRequest initiatingRequest = (FtpWebRequest)base.m_Request;
                TlsStream     stream3           = new TlsStream(initiatingRequest.RequestUri.Host, networkStream, initiatingRequest.ClientCertificates, base.Pool.ServicePoint, initiatingRequest, base.m_Async ? initiatingRequest.GetWritingContext().ContextCopy : null);
                networkStream = stream3;
                if (base.m_Async)
                {
                    this.m_TlsStream = stream3;
                    LazyAsyncResult result = new LazyAsyncResult(null, this, m_SSLHandshakeCallback);
                    stream3.ProcessAuthentication(result);
                    return(CommandStream.PipelineInstruction.Pause);
                }
                stream3.ProcessAuthentication(null);
            }
            stream = new FtpDataStream(networkStream, (FtpWebRequest)base.m_Request, this.IsFtpDataStreamWriteable());
            return(CommandStream.PipelineInstruction.GiveStream);
        }
        protected override CommandStream.PipelineInstruction PipelineCallback(CommandStream.PipelineEntry entry, ResponseDescription response, bool timeout, ref Stream stream)
        {
            if (response == null)
            {
                return(CommandStream.PipelineInstruction.Abort);
            }
            FtpStatusCode status = (FtpStatusCode)response.Status;

            if (status != FtpStatusCode.ClosingControl)
            {
                this.StatusCode = status;
                this.StatusLine = response.StatusDescription;
            }
            if (response.InvalidStatusCode)
            {
                throw new WebException(SR.GetString("net_InvalidStatusCode"), WebExceptionStatus.ProtocolError);
            }
            if (base.m_Index == -1)
            {
                switch (status)
                {
                case FtpStatusCode.SendUserCommand:
                    this.m_BannerMessage = new StringBuilder();
                    this.m_BannerMessage.Append(this.StatusLine);
                    return(CommandStream.PipelineInstruction.Advance);

                case FtpStatusCode.ServiceTemporarilyNotAvailable:
                    return(CommandStream.PipelineInstruction.Reread);
                }
                throw base.GenerateException(status, response.StatusDescription, null);
            }
            if (entry.Command == "OPTS utf8 on\r\n")
            {
                if (response.PositiveCompletion)
                {
                    base.Encoding = Encoding.UTF8;
                }
                else
                {
                    base.Encoding = Encoding.Default;
                }
                return(CommandStream.PipelineInstruction.Advance);
            }
            if (entry.Command.IndexOf("USER") != -1)
            {
                if (status == FtpStatusCode.LoggedInProceed)
                {
                    this.m_LoginState = FtpLoginState.LoggedIn;
                    base.m_Index++;
                }
                else if ((status == FtpStatusCode.NotLoggedIn) && (this.m_LoginState != FtpLoginState.NotLoggedIn))
                {
                    this.m_LoginState = FtpLoginState.ReloginFailed;
                    throw ExceptionHelper.IsolatedException;
                }
            }
            if (response.TransientFailure || response.PermanentFailure)
            {
                if (status == FtpStatusCode.ServiceNotAvailable)
                {
                    base.MarkAsRecoverableFailure();
                }
                throw base.GenerateException(status, response.StatusDescription, null);
            }
            if ((this.m_LoginState != FtpLoginState.LoggedIn) && (entry.Command.IndexOf("PASS") != -1))
            {
                switch (status)
                {
                case FtpStatusCode.NeedLoginAccount:
                case FtpStatusCode.LoggedInProceed:
                    this.m_LoginState = FtpLoginState.LoggedIn;
                    goto Label_017A;
                }
                throw base.GenerateException(status, response.StatusDescription, null);
            }
Label_017A:
            if (entry.HasFlag(CommandStream.PipelineEntryFlags.CreateDataConnection) && (response.PositiveCompletion || response.PositiveIntermediate))
            {
                bool flag;
                CommandStream.PipelineInstruction instruction = this.QueueOrCreateDataConection(entry, response, timeout, ref stream, out flag);
                if (!flag)
                {
                    return(instruction);
                }
            }
            switch (status)
            {
            case FtpStatusCode.OpeningData:
            case FtpStatusCode.DataAlreadyOpen:
            {
                if (this.m_DataSocket == null)
                {
                    return(CommandStream.PipelineInstruction.Abort);
                }
                if (!entry.HasFlag(CommandStream.PipelineEntryFlags.GiveDataStream))
                {
                    base.m_AbortReason = SR.GetString("net_ftp_invalid_status_response", new object[] { status, entry.Command });
                    return(CommandStream.PipelineInstruction.Abort);
                }
                this.TryUpdateContentLength(response.StatusDescription);
                FtpWebRequest request = (FtpWebRequest)base.m_Request;
                if (request.MethodInfo.ShouldParseForResponseUri)
                {
                    this.TryUpdateResponseUri(response.StatusDescription, request);
                }
                return(this.QueueOrCreateFtpDataStream(ref stream));
            }

            case FtpStatusCode.LoggedInProceed:
                this.m_WelcomeMessage.Append(this.StatusLine);
                break;

            case FtpStatusCode.ClosingControl:
                this.m_ExitMessage.Append(response.StatusDescription);
                base.CloseSocket();
                break;

            case FtpStatusCode.ServerWantsSecureSession:
            {
                FtpWebRequest initiatingRequest = (FtpWebRequest)base.m_Request;
                TlsStream     stream2           = new TlsStream(initiatingRequest.RequestUri.Host, base.NetworkStream, initiatingRequest.ClientCertificates, base.Pool.ServicePoint, initiatingRequest, base.m_Async ? initiatingRequest.GetWritingContext().ContextCopy : null);
                base.NetworkStream = stream2;
                break;
            }

            case FtpStatusCode.FileStatus:
            {
                FtpWebRequest request1 = (FtpWebRequest)base.m_Request;
                if (entry.Command.StartsWith("SIZE "))
                {
                    this.m_ContentLength = this.GetContentLengthFrom213Response(response.StatusDescription);
                }
                else if (entry.Command.StartsWith("MDTM "))
                {
                    this.m_LastModified = this.GetLastModifiedFrom213Response(response.StatusDescription);
                }
                break;
            }

            default:
                if (status == FtpStatusCode.PathnameCreated)
                {
                    if ((entry.Command == "PWD\r\n") && !entry.HasFlag(CommandStream.PipelineEntryFlags.UserCommand))
                    {
                        this.m_LoginDirectory = this.GetLoginDirectory(response.StatusDescription);
                    }
                }
                else if (entry.Command.IndexOf("CWD") != -1)
                {
                    this.m_EstablishedServerDirectory = this.m_RequestedServerDirectory;
                }
                break;
            }
            if (!response.PositiveIntermediate && (base.UsingSecureStream || !(entry.Command == "AUTH TLS\r\n")))
            {
                return(CommandStream.PipelineInstruction.Advance);
            }
            return(CommandStream.PipelineInstruction.Reread);
        }