diff --git a/src/Renci.SshNet/ConnectionInfo.cs b/src/Renci.SshNet/ConnectionInfo.cs index 17bc1a810..aab50c3c4 100644 --- a/src/Renci.SshNet/ConnectionInfo.cs +++ b/src/Renci.SshNet/ConnectionInfo.cs @@ -51,6 +51,7 @@ public class ConnectionInfo : IConnectionInfoInternal private TimeSpan _timeout; private TimeSpan _channelCloseTimeout; + private TimeSpan _sendTimeout = System.Threading.Timeout.InfiniteTimeSpan; /// /// Gets supported key exchange algorithms for this connection. @@ -191,6 +192,25 @@ public TimeSpan ChannelCloseTimeout } } + /// + /// Gets or sets the socket send timeout. Controls how long a socket send may block before + /// throwing a . The default value is + /// (no timeout). + /// + public TimeSpan SendTimeout + { + get + { + return _sendTimeout; + } + set + { + value.EnsureValidTimeout(nameof(SendTimeout)); + + _sendTimeout = value; + } + } + /// /// Gets or sets the character encoding. /// diff --git a/src/Renci.SshNet/Session.cs b/src/Renci.SshNet/Session.cs index 5468b53c8..89c12e4cd 100644 --- a/src/Renci.SshNet/Session.cs +++ b/src/Renci.SshNet/Session.cs @@ -602,6 +602,8 @@ public void Connect() _socket = _serviceFactory.CreateConnector(ConnectionInfo, _socketFactory) .Connect(ConnectionInfo); + _socket.SendTimeout = ConnectionInfo.SendTimeout.AsTimeout(); + var serverIdentification = _serviceFactory.CreateProtocolVersionExchange() .Start(ClientVersion, _socket, ConnectionInfo.Timeout); @@ -727,6 +729,8 @@ public async Task ConnectAsync(CancellationToken cancellationToken) _socket = await _serviceFactory.CreateConnector(ConnectionInfo, _socketFactory) .ConnectAsync(ConnectionInfo, cancellationToken).ConfigureAwait(false); + _socket.SendTimeout = ConnectionInfo.SendTimeout.AsTimeout(); + var serverIdentification = await _serviceFactory.CreateProtocolVersionExchange() .StartAsync(ClientVersion, _socket, cancellationToken).ConfigureAwait(false);