FTP control channel.
Inheritance: IDisposable
Exemplo n.º 1
0
        /// <summary>
        /// Releases the unmanaged resources used by the <see cref="FtpSessionConnected"/> object and optionally releases the managed resources.
        /// </summary>
        /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
        protected virtual void Dispose(bool disposing)
        {
            if (!m_disposed)
            {
                try
                {
                    // This will be done regardless of whether the object is finalized or disposed.

                    if (disposing)
                    {
                        m_host    = null;
                        m_root    = null;
                        m_current = null;

                        if ((object)m_ctrlChannel != null)
                        {
                            m_ctrlChannel.Close();
                        }

                        m_ctrlChannel = null;

                        if ((object)m_dataStream != null)
                        {
                            m_dataStream.Dispose();
                        }

                        m_dataStream = null;
                    }
                }
                finally
                {
                    m_disposed = true;  // Prevent duplicate dispose.
                }
            }
        }
Exemplo n.º 2
0
 internal FtpSessionConnected(FtpClient h, FtpControlChannel ctrl, bool caseInsensitive)
 {
     m_host                = h;
     m_ctrlChannel         = ctrl;
     m_ctrlChannel.Session = this;
     m_caseInsensitive     = caseInsensitive;
 }
Exemplo n.º 3
0
        public void Connect(string userName, string password)
        {
            FtpControlChannel ctrl = new FtpControlChannel(m_host);

            ctrl.Server = m_server;
            ctrl.Port   = m_port;
            ctrl.Connect();

            try
            {
                ctrl.Command("USER " + userName);

                if (ctrl.LastResponse.Code == FtpResponse.UserAcceptedWaitingPass)
                {
                    ctrl.Command("PASS " + password);
                }

                if (ctrl.LastResponse.Code != FtpResponse.UserLoggedIn)
                {
                    throw new FtpAuthenticationException("Failed to login.", ctrl.LastResponse);
                }

                m_host.State = new FtpSessionConnected(m_host, ctrl, m_caseInsensitive);
                ((FtpSessionConnected)m_host.State).InitRootDirectory();
            }
            catch
            {
                ctrl.Close();
                throw;
            }
        }
Exemplo n.º 4
0
 internal FtpSessionConnected(FtpClient h, FtpControlChannel ctrl, bool caseInsensitive)
 {
     m_host = h;
     m_ctrlChannel = ctrl;
     m_ctrlChannel.Session = this;
     m_caseInsensitive = caseInsensitive;
 }
Exemplo n.º 5
0
 internal FtpDataStream(FtpControlChannel ctrl, TcpClient client)
 {
     m_session   = ctrl.Session;
     m_ctrl      = ctrl;
     m_tcpClient = client;
     m_stream    = client.GetStream();
     m_session.BeginDataTransfer(this);
 }
Exemplo n.º 6
0
 internal FtpDataStream(FtpControlChannel ctrl, TcpClient client)
 {
     m_session = ctrl.Session;
     m_ctrl = ctrl;
     m_tcpClient = client;
     m_stream = client.GetStream();
     m_session.BeginDataTransfer(this);
 }
Exemplo n.º 7
0
 internal FtpDataStream(FtpControlChannel ctrl, TcpClient client)
 {
     m_session             = ctrl.Session;
     m_ctrl                = ctrl;
     m_tcpClient           = client;
     m_stream              = client.GetStream();
     m_stream.ReadTimeout  = ctrl.Timeout;
     m_stream.WriteTimeout = ctrl.Timeout;
     TryBeginDataTransfer();
 }
Exemplo n.º 8
0
 internal FtpInputDataStream(FtpControlChannel ctrl, TcpClient client)
     : base(ctrl, client)
 {
 }
Exemplo n.º 9
0
 internal FtpOutputDataStream(FtpControlChannel ctrl, TcpClient client)
     : base(ctrl, client)
 {
 }
Exemplo n.º 10
0
        /// <summary>
        /// Releases the unmanaged resources used by the <see cref="FtpSessionConnected"/> object and optionally releases the managed resources.
        /// </summary>
        /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
        protected virtual void Dispose(bool disposing)
        {
            if (!m_disposed)
            {
                try
                {
                    // This will be done regardless of whether the object is finalized or disposed.

                    if (disposing)
                    {
                        m_host = null;
                        m_root = null;
                        m_current = null;

                        if ((object)m_ctrlChannel != null)
                            m_ctrlChannel.Close();

                        m_ctrlChannel = null;

                        if ((object)m_dataStream != null)
                            m_dataStream.Dispose();

                        m_dataStream = null;
                    }
                }
                finally
                {
                    m_disposed = true;  // Prevent duplicate dispose.
                }
            }
        }
Exemplo n.º 11
0
        public void Connect(string userName, string password)
        {
            FtpControlChannel ctrl = new FtpControlChannel(m_host);

            ctrl.Server = m_server;
            ctrl.Port = m_port;
            ctrl.Connect();

            try
            {
                ctrl.Command("USER " + userName);

                if (ctrl.LastResponse.Code == FtpResponse.UserAcceptedWaitingPass)
                    ctrl.Command("PASS " + password);

                if (ctrl.LastResponse.Code != FtpResponse.UserLoggedIn)
                    throw new FtpAuthenticationException("Failed to login.", ctrl.LastResponse);

                m_host.State = new FtpSessionConnected(m_host, ctrl, m_caseInsensitive);
                ((FtpSessionConnected)m_host.State).InitRootDirectory();
            }
            catch
            {
                ctrl.Close();
                throw;
            }
        }