0 votes
by (120 points)
edited

Hi,

I try to connect to the sFTP server. May be it is too busy and I can connect to it only after ~30sec (using for example WinSCP client). But using Rebex on the 20th second I got timeout exception (see details below). Timeout property is not affect on it (it is set to the 300*1000).

Thank you!

Exception stacktrace:

Rebex.Net.ProxySocketException: 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. ---> Rebex.Net.ProxySocketException: 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. ---> System.Net.Sockets.SocketException: 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 [server address]:22
   at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
   at System.Net.Sockets.Socket.Connect(EndPoint remoteEP)
   at wWGvS.BnRMAeZ.kRCyw(String , IPAddress , Int32 )
   --- End of inner exception stack trace ---
   at wWGvS.BnRMAeZ.kRCyw(String , IPAddress , Int32 )
   --- End of inner exception stack trace ---
   at wWGvS.BnRMAeZ.YqGDG(IAsyncResult , String )
   at wWGvS.BnRMAeZ.cCoahHZ(IAsyncResult , Int32 )
   at Rebex.Net.ProxySocket.Connect(String serverName, Int32 serverPort)
   at Rebex.Net.Sftp.Connect(String serverName, Int32 serverPort, SshParameters parameters)
* Rebex.Net.SftpException: 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. ---> Rebex.Net.SftpException: 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. ---> Rebex.Net.ProxySocketException: 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. ---> Rebex.Net.ProxySocketException: 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. ---> System.Net.Sockets.SocketException: 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 [server address]6:22
   at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
   at System.Net.Sockets.Socket.Connect(EndPoint remoteEP)
   at wWGvS.BnRMAeZ.kRCyw(String , IPAddress , Int32 )
   --- End of inner exception stack trace ---
   at wWGvS.BnRMAeZ.kRCyw(String , IPAddress , Int32 )
   --- End of inner exception stack trace ---
   at wWGvS.BnRMAeZ.YqGDG(IAsyncResult , String )
   at wWGvS.BnRMAeZ.cCoahHZ(IAsyncResult , Int32 )
   at Rebex.Net.ProxySocket.Connect(String serverName, Int32 serverPort)
   at Rebex.Net.Sftp.Connect(String serverName, Int32 serverPort, SshParameters parameters)
   --- End of inner exception stack trace ---
   at Rebex.Net.Sftp.Connect(String serverName, Int32 serverPort, SshParameters parameters)
   --- End of inner exception stack trace ---
   at Rebex.Net.Sftp.YqGDG(IAsyncResult , MethodBase )
   at Rebex.Net.Sftp.EndConnect(IAsyncResult asyncResult)
Applies to: Rebex SFTP

1 Answer

0 votes
by (147k points)
edited

This exception was thrown by .NET's Socket class as a result of an error reported by Winsock, Windows TCP subsystem. Winsock has its own timeout values and some of them (including Connect timeout) can't be affected by applications.

If interested, check out the Winsock FAQ for more information – while it is possible for an application to make connection attempts fail sooner than TCP subsystem timeout occurs (and the FAQ describes how), it's not possible to make it wait longer. If the Connect method times out after 20 seconds, we can't change that.

However, this should affect all applications including WinSCP. Perhaps WinSCP tries re-connecting after it gets this kind of error? You can reproduce that kind of behavior with Rebex SFTP as well - catch the SftpException thrown by the Connect method, check its Status or Inner Exceptions to make sure it's this error and try again if needed.

by (120 points)
edited

But you can use non blocking Socket.BeginConnect method instead Socket.Connect.

For example: http://stackoverflow.com/questions/1062035/how-to-config-socket-connect-timeout-in-c

by (147k points)
edited

Unfortunately, non-blocking BeginConnect would time out as well. Even the example in the link discusses ways to make it time out sooner (which is possible, as I stated above), not ways to make it time out later.

Try the following code:

using System.Net;
using System.Net.Sockets;
...

Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IAsyncResult ar = socket.BeginConnect(serverName, 22, null, null);
socket.EndConnect(ar);
...