Topic "Server timeout doesn't work with .NET Assembly"

Author Message
irina

Guest


In our company we use .NET Assembly (winscpnet.dll) and WinScp utility to upload files on SFTP server. A connection with some of SFTP servers is very slow. So default 15 seconds connection timeout is not enough. We set different timeout in SessionOptions object and pass it to Session Open method, but it doesn't change the actual connection timeout (e.g. we set 5 mins timeout, call Open method and get timeout exception with message "Network error: Connection to [ip address] timed out." in about 15-20 seconds).

Open session call example:

Code:
 
  SessionOptions sessionOptions = new SessionOptions
  {
     Protocol = Protocol.Sftp,
     HostName = host,
     UserName = userName,
     Password = password,
     PortNumber = port,
     SshHostKeyFingerprint = hostKeyFingerPrint,
     Timeout = new TimeSpan(0, 5, 0)
  };

  _session.Open(sessionOptions);


In Log file we see that the following commands are executed and timeout parameter has the right value 300 seconds:

Code:
option batch on
option confirm off
option reconnecttime 120
open "sftp://username:***@10.11.178.20:22" -hostkey="ssh-ed25519 256 86:ff:cb:71:7a:e7:46:36:31:b2:26:01:a7:ec:a1:96" -timeout=300


Using WinSCP 5.11.1 on Windows 10 (also it is reproduced on Windows Server 2012 R2). Debug log file is attached.
TimeoutIssueLog.log (45.05 KB) Private file

Description: Debug log file.

Advertisements
martin◆
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 27083
Location: Prague, Czechia
It's ultimately on the operating system how long it will keep waiting for the connection.

Wouldn't it help it you retry the connection immediately after the timeout?
irina
[View user's profile]

Joined: 2017-09-13
Posts: 2
Location: Russia
Could you please clarify does it make sense to try to do it if we have persistent slow connection? E.g. the default server reponse timeout is 15 seconds, we retry connection immediately after the timeout and it works. Will we be able to upload files to a server if time to get a server response is more that 15 seconds?
martin◆
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 27083
Location: Prague, Czechia
Once you get connected, the SessionOptions.Timeout does apply unconditionally (contrary to connection timeout, where system may enforce its own timeout). So increasing it will help.
irina
[View user's profile]

Joined: 2017-09-13
Posts: 2
Location: Russia
martin wrote:
It's ultimately on the operating system how long it will keep waiting for the connection.

Wouldn't it help it you retry the connection immediately after the timeout?


Seems that this solution doesn't work. I tested it in the following way:

1. Got timeout time between Session Open method call and timeout exception on my local machine. It is always was about 23000 ms.
2. In a network emulator tool set latency for full package trip 24000ms (also tried 26000, 28000, 30000).
3. In a code added addtional Session Open method call right after getting of timeout exception (I got timeout exception for this call again).

So could you please confirm that the test scenario described above is appropriate? If it is true, may be there is another way to fix this issue?

Thank you
martin◆
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 27083
Location: Prague, Czechia
If the OS timeouts the connection before the server replies, then indeed no matter how many retries you do, it will never connect.
But I understood that your real server does not respond that late always, that's why I've suggested the retry.
Anyway, are you able to reliably connect using any other SSH/SFTP client?
Advertisements

You can post new topics in this forum

Search

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License