Пример #1
0
        /// <summary>
        /// Disconnects client from the server.
        /// </summary>
        /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
        public void Disconnect()
        {
            CheckDisposed();

            OnDisconnecting();

            // stop sending keep-alive messages before we close the
            // session
            StopKeepAliveTimer();

            // disconnect and dispose the SSH session
            if (Session != null)
            {
                // a new session is created in Connect(), so we should dispose and
                // dereference the current session here
                Session.ErrorOccured    -= Session_ErrorOccured;
                Session.HostKeyReceived -= Session_HostKeyReceived;
                Session.Disconnect();
                Session.Dispose();
                Session = null;
            }

            OnDisconnected();
        }