Retrying Script/Connection Attempt

The following batch file retries failed script after set interval. You can use it, when the server tends to be temporarily unavailable (WinSCP does not retry an initial connection attempt automatically).

@echo off
set TRIES=3
:retry /script=script.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

Further Reading


Last modified: by martin