WinSCP script hangs when connecting to host

1

1

I've batch script that runs winscp with script, and sometimes WinSCP hangs when is "Connecting to host".

Is it possible to set timeout that WinSCP stops trying to connect and shuts it's self after x seconds when cannot connect?

R. Nec

Posted 2015-03-17T13:34:44.740

Reputation: 69

I had a similar issue with WinSCP a few years ago which led to my discovery of the WinSCP forums where any of the threads are answered by the main developer himself.

– Tyson – 2015-03-17T13:43:41.110

Does it "hang" or does it keep re-trying to connect? – Martin Prikryl – 2015-03-17T14:29:35.413

@Martin Pikryl, wscp prompts Connecting to host and waits infinitely. – R. Nec – 2015-03-17T14:45:54.947

Please include a WinSCP session log file. – Martin Prikryl – 2015-03-17T15:02:34.530

Answers

1

On you open command you can set a timeout parameter

-timeout=<sec>

Example:

open sftp://martin:mypassword@example.com/ -hostkey="ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx" -timeout=30

developer__c

Posted 2015-03-17T13:34:44.740

Reputation: 232

1

A default timeout is 15 seconds. You can change it using the -timeout switch of the open command. Though in some cases, Windows does not respect the timeout and may use longer (or shorter).

When a connection fails (or times out), WinSCP will retry the connection. In the default "batch" mode, WinSCP will keep re-trying for up to 2 minutes. In an interactive mode, it keeps trying forever.

You can change the limit using the option reconnecttime <sec> command.

Examples:

option batch abort
option reconnecttime 60
open sftp://user@example.com/ -timeout=15

Martin Prikryl

Posted 2015-03-17T13:34:44.740

Reputation: 13 764

When using option reconnectime 60 I get Unknown option 'reconnectime'.. Try instead using reconnecttime. – Arvo Bowen – 2018-08-09T21:38:18.770

@ArvoBowen Thanks, I've corrected my answer. – Martin Prikryl – 2018-08-10T05:11:44.613