0 votes
by (150 points)
edited by

Hi,

I'm trying your component. And I see have problem with SshSession timeout. I tried set timeout = 1000 ms (=1s) or 100000 ms(=100s) but it's not working, seem that it only connect with default timeout is 60s. Please fix it

var session = new SshSession();

session.Timeout = 1000;
session.Connect(IPAddress);
session.Authenticate(UserName, Password);

1 Answer

0 votes
by (147k points)
edited by
 
Best answer

Update: This has been fixed in version 2016 R2 of Rebex SFTP and Rebex Terminal Emulation.


Hi, thanks for letting us know about this problem. We will fix it for the next release.

In the meantime, you can use the following workaround:

int timeout = 1000;

var socket = new ProxySocket();
var ar = socket.BeginConnect(IPAddress, 22, null, null);
if (!ar.AsyncWaitHandle.WaitOne(timeout))
{
    socket.Close();
    throw new ProxySocketException("Operation timed out.", ProxySocketExceptionStatus.Timeout);
}
socket.EndConnect(ar);

var session = new SshSession(socket);
session.Timeout = timeout;
session.Negotiate();
session.Authenticate(UserName, Password);
by (150 points)
Thank you. I tried and it work with small timeout (eg int timeout = 1000, it will show excaption Operation timed out.). But when I set high timout, eg timeout = 100000, it will timeout after 30s only, not wait with full timeout that I set. Please check and fix
by (147k points)
What exception message do you get when it times out after 30 seconds? It's quite possible this is the correct behavior. The Timeout property is used to specify the maximum acceptable duration of the operation, but it does not prevent the internals from failing sooner. This is actually quite common - some values (such as connection timeouts for TCP sockets) can't be controlled by applications, which means we can't make the TCP connection attempts fail later.
by (150 points)
Hi,
I received the message exception "A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond." Please check
by (147k points)
Thanks. This is actually an example of a failure that can't be postponed without changing system-wide TCP subsystem settings. Simply said, an application can't make TCP socket connection attempt last longer. The following .NET code demonstrates the same behavior:
            var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            socket.Connect("1.2.3.4", 22);
Note that there is no Socket option that could be used to make the connection attempt last longer. The same applies to our components which use .NET Socket class internally.
...