Use TrySendMessage to send SSH_MSG_DISCONNECT, SSH_MSG_CHANNEL_EOF, SSH_MSG_CHANNEL_CLOSE and SSH_MSG_IGNORE messages to avoid throwing exceptions while closing/disposing or sending keep-alive messages.
Avoid sending multiple keep-alive messages concurrently for the same client.
Fixed regression in multi-factor authentication.
* Only send SSH_MSG_CHANNEL_EOF message to remote party when we haven't received a SSH_MSG_CHANNEL_EOF or SSH_MSG_CHANNEL_CLOSE message from the remote party.
* Move logic for sending SSH_MSG_CHANNEL_EOF message from derived classes and client classes into Channel.Close(bool) method.
* Move initialization to ctor.
ChannelSession:
* Avoid leaking session semaphores.
SftpFileStream:
* Modify CanRead, CanWrite and CanSeek to return false when the stream is disposed.
* Modify other public members to throw ObjectDisposedException when the stream is disposed or the SFTP session is no longer open.
* Modify Dispose to only flush the write buffer and/or close the SFTP file handle when the SFTP session is open.
* No longer flush write buffer or close SFTP file handle in finalizer. Fixes issue #2013.
Session:
* Remove CreateClientChannel<T> and CreateServerChannel<T> methods; use specific constructors of channels instead.
SftpClient:
* BufferSize was not used for AppendText(String, Encoding) and Create(String) overloads.
SubsystemSession:
* Added IsOpen property.
* Throw ObjectDisposedException in all public members - except for IsOpen - when the session is disposed.
* Throw InvalidOperationException in all public members - except for Connect and IsOpen - when the session is not open.
* Modify Disconnect to release managed resources that are linked to the connected session.
* Modify Dispose to use Disconnect to managed resources that are linked to the connected session.
Unit tests:
* Added large set of tests for changes listed above.
* Tests for which the code was automatically, and that are not yet correctly implemented, are now marked as Ignore.
* Tests that require a (specifically configured) running SSH server are now marked with test category "integration".
The SSH_MSG_CHANNEL_EOF message is now only sent from Close(bool), and we now only ever wait for an SSH_MSG_CHANNEL_CLOSE message once the client has shut down.
The SSH_MSG_CHANNEL_EOF which is sent by the server is now only used to interrupt the blocking receive on the client socket, and close it.
* Improve robustness of channels by not letting an exception - that occurs while processing events signaled by session - up to session where this would cause the message loop to interrupt, and hence the SSH client would be disconnected.
Instead, exceptions that are thrown during processing of session events are now signaled using a new Exception event.
* Renamed RequestSuccessed event to RequestSucceeded, fixing a typo.
ChannelDirectTcpip:
* Interrupt blocking receive when forwarded port is closing allowing for a clean close of the channel.
* Send SSH_MSG_CHANNEL_EOF to server when client quits sending data.
ChannelForwardedTcpip:
* Interrupt blocking receive when forwarded port is closing or when an error occurs in the session allowing for a clean close of the channel.
ForwardedPortDynamic:
* When stopping the port, signal all channels that the port is closing and wait for the channels to close.
* Modify Start() and Stop() to throw ObjectDisposedException when instance is disposed.
* Modify Dispose() to also interrupt blocking receive and wait for the channels to close.
* Fixed IPv6 support for SOCKS5.
* Signal exceptions in channels using the Exception event on the forwarded port.
ForwardedPortLocal:
* When stopping the port, signal all channels that the port is closing and wait for the channels to close.
* Modify Start() and Stop() to throw ObjectDisposedException when instance is disposed.
* Modify Dispose() to also interrupt blocking receive and wait for the channels to close.
* Signal exceptions in channels using the Exception event on the forwarded port.
ForwardedPortRemote:
* When stopping the port, cancel the tcpip-forward, interrupt pending channels and for the channels to close.
* Modify Start() and Stop() to throw ObjectDisposedException when instance is disposed.
* Modify Dispose() to also cancel the tcpip-forward, interrupt pending channels and for the channels to close.
* Signal exceptions in channels using the Exception event on the forwarded port.
Overall:
* Add huge set of unit tests for channels and forwarded ports.
Added internal IChannelDirectTcpip and IChannelForwardedTcpip interfaces.
Extended ISession and IConnection interface to allow for unit tests of ChannelDirectTcpip.
Modified ChannelDirectTcpip to interrupt blocking receive when the ForwardedPort is closed.
Shutdown send of socket when EOF is received.
Close the socket when unhandled exception occurs in session message loop, and when server terminates connection using SSH_MSG_DISCONNECT message.
Fixes issue #1558.
When stopping ForwardedLocalPort, block until all channels have been closed or until Connection.Timeout has elapsed.
Added SftpPathNotFoundException to doc for SftpClient.Get(String) and SftpClient.GetAttributes(String).
Do not throw exception in Session.Disconnect() and Session.Dispose() when socket is not connected.
Fixes issue #2148.