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?

  • 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 Mar 17 '15 at 13:43
  • Does it "hang" or does it keep re-trying to connect? – Martin Prikryl Mar 17 '15 at 14:29
  • @Martin Pikryl, wscp prompts Connecting to host and waits infinitely. – R. Nec Mar 17 '15 at 14:45
  • Please include a WinSCP session log file. – Martin Prikryl Mar 17 '15 at 15:02

On you open command you can set a timeout parameter



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

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.


option batch abort
option reconnecttime 60
open sftp://user@example.com/ -timeout=15
  • When using option reconnectime 60 I get Unknown option 'reconnectime'.. Try instead using reconnecttime. – Arvo Bowen Aug 9 '18 at 21:38
  • @ArvoBowen Thanks, I've corrected my answer. – Martin Prikryl Aug 10 '18 at 5:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.