/// <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. } } }
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; } }
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; } }