The FtpDataStream class implements the FTP data connection.

Inheritance: System.IO.Stream, ICloseEx
        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);
        }
Beispiel #2
0
        //    Creates a FtpDataStream object, constructs a TLS stream if needed.
        //    In case SSL and ASYNC we delay sigaling the user stream until the handshake is done.
        private PipelineInstruction QueueOrCreateFtpDataStream(ref Stream stream)
        {
            if (_dataSocket == null)
            {
                throw new InternalException();
            }

            //
            // Re-entered pipeline with completed read on the TlsStream
            //
            if (_tlsStream != null)
            {
                stream     = new FtpDataStream(_tlsStream, (FtpWebRequest)_request, IsFtpDataStreamWriteable());
                _tlsStream = null;
                return(PipelineInstruction.GiveStream);
            }

            NetworkStream networkStream = new NetworkStream(_dataSocket, true);

            if (UsingSecureStream)
            {
                FtpWebRequest request = (FtpWebRequest)_request;

                TlsStream tlsStream = new TlsStream(networkStream, _dataSocket, request.RequestUri.Host, request.ClientCertificates);
                networkStream = tlsStream;

                if (_isAsync)
                {
                    _tlsStream = tlsStream;

                    tlsStream.BeginAuthenticateAsClient(s_SSLHandshakeCallback, this);
                    return(PipelineInstruction.Pause);
                }
                else
                {
                    tlsStream.AuthenticateAsClient();
                }
            }

            stream = new FtpDataStream(networkStream, (FtpWebRequest)_request, IsFtpDataStreamWriteable());
            return(PipelineInstruction.GiveStream);
        }
Beispiel #3
0
        //    Creates a FtpDataStream object, constructs a TLS stream if needed.
        //    In case SSL and ASYNC we delay sigaling the user stream until the handshake is done.
        private PipelineInstruction QueueOrCreateFtpDataStream(ref Stream stream)
        {
            if (_dataSocket == null)
                throw new InternalException();

            //
            // Re-entered pipeline with completed read on the TlsStream
            //
            if (_tlsStream != null)
            {
                stream = new FtpDataStream(_tlsStream, (FtpWebRequest)_request, IsFtpDataStreamWriteable());
                _tlsStream = null;
                return PipelineInstruction.GiveStream;
            }

            NetworkStream networkStream = new NetworkStream(_dataSocket, true);

            if (UsingSecureStream)
            {
                FtpWebRequest request = (FtpWebRequest)_request;

                TlsStream tlsStream = new TlsStream(networkStream, _dataSocket, request.RequestUri.Host, request.ClientCertificates);
                networkStream = tlsStream;

                if (_isAsync)
                {
                    _tlsStream = tlsStream;

                    tlsStream.BeginAuthenticateAsClient(s_SSLHandshakeCallback, this);
                    return PipelineInstruction.Pause;
                }
                else
                {
                    tlsStream.AuthenticateAsClient();
                }
            }

            stream = new FtpDataStream(networkStream, (FtpWebRequest)_request, IsFtpDataStreamWriteable());
            return PipelineInstruction.GiveStream;
        }
Beispiel #4
0
        //    Creates a FtpDataStream object, constructs a TLS stream if needed.
        //    In case SSL we issue a 0 bytes read on that stream to force handshake.
        //    In case SSL and ASYNC we delay sigaling the user stream until the handshake is done.
        //
        private PipelineInstruction QueueOrCreateFtpDataStream(ref Stream stream)
        {
            if (m_DataSocket == null)
                throw new InternalException();

            //
            // Re-entered pipeline with completed read on the TlsStream
            //
            if (this.m_TlsStream != null )
            {
                stream = new FtpDataStream(this.m_TlsStream, (FtpWebRequest) m_Request, IsFtpDataStreamWriteable());
                this.m_TlsStream = null;
                return  PipelineInstruction.GiveStream;
            }

            NetworkStream networkStream = new NetworkStream(m_DataSocket, true);

#if !FEATURE_PAL
            if (UsingSecureStream)
            {
                FtpWebRequest request = (FtpWebRequest) m_Request;

                TlsStream tlsStream = new TlsStream(request.RequestUri.Host, networkStream, request.ClientCertificates, Pool.ServicePoint, request, m_Async ? request.GetWritingContext().ContextCopy : null);
                networkStream = tlsStream;

                if (m_Async)
                {
                    this.m_TlsStream = tlsStream;
                    LazyAsyncResult handshakeResult = new LazyAsyncResult(null, this, m_SSLHandshakeCallback);
                    tlsStream.ProcessAuthentication(handshakeResult);
                    return PipelineInstruction.Pause;
                }
                else
                {
                    tlsStream.ProcessAuthentication(null);
                }
            }
#endif // !FEATURE_PAL
            stream = new FtpDataStream(networkStream, (FtpWebRequest) m_Request, IsFtpDataStreamWriteable());
            return  PipelineInstruction.GiveStream;
        }
        //    Creates a FtpDataStream object, constructs a TLS stream if needed.
        //    In case SSL we issue a 0 bytes read on that stream to force handshake.
        //    In case SSL and ASYNC we delay sigaling the user stream until the handshake is done.
        //
        private PipelineInstruction QueueOrCreateFtpDataStream(ref Stream stream)
        {
            if (m_DataSocket == null)
                throw new InternalException();


            NetworkStream networkStream = new NetworkStream(m_DataSocket, true);

            stream = new FtpDataStream(networkStream, (FtpWebRequest) m_Request, IsFtpDataStreamWriteable());
            return  PipelineInstruction.GiveStream;
        }
 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;
 }