@echo off set TRIES=7 set INTERVAL=4 :retry "c:\Program Files (x86)\WinSCP\WinSCP.com" /console /script="c:\Program Files (x86)\WinSCP\UploadScript.txt" if %ERRORLEVEL% neq 0 ( set /A TRIES=%TRIES%-1 if %TRIES% gtr 1 ( echo Failed, retrying in %INTERVAL% seconds... timeout /t %INTERVAL% goto retry ) else ( echo Failed, aborting exit /b 1 ) ) echo Success exit /b 0
open bupload option batch on synchronize remote "c:\source" "\" exit
Because the internet in the country is very unstable, the connection will drop for seconds at a time. And this will cause an error whilst the software is comparing the content in the file:
Comparing... Local 'c:\source\2017-09-05' => Remote '\/2017-09-05' Local 'c:\source\2017-09-06' => Remote '\/2017-09-06' Local 'c:\source\2017-09-07' => Remote '\/2017-09-07' Error listing directory '\/2017-09-07'. Could not retrieve directory listing Could not create socket. (A)bort, (R)etry, (S)kip: Abort
As you can see it successfully receives the directory listing for the first few directories (2017-09-05 to 2017-09-06). But then it fails and automatically aborts at 2017-09-07. This happens randomly. If I run the app again it will fail at a different directory. Sometimes it doesn't even fail at all.
I would like the program to automatically try to retrieve the directory listing again if it fails because if it keeps trying it will eventually succeed (because the internet becomes stable).
My batch file has a work-around that detects if the program exits with an error and then restarts the app entirely (7 times) but this will then cause it to start comparing from the first directory again (leaving more room for connection errors to occur).
Is this possible?