Script ERRORLEVEL not working as expexted

Advertisement

ericcao
Joined:
Posts:
2
Location:
canada

Script ERRORLEVEL not working as expexted

Hi,

We are trying to transfer some files to client FTP server and it needs to stop transfer whenever it detects an error (client FTP server is not stable).

We use a batch script like this:
cd /d %~dp0
".\WinSCP\WinSCP.exe" /script=.\FTP_Outbound.txt /log=.\FTP_Outbound_log.txt /logsize=5*10M
if %ERRORLEVEL% NEQ 0 (
    echo WinSCP transfer failed. Files will not be moved.
    exit /b %ERRORLEVEL%
)
cd /d D:\Exports\
rem Move files to Backup folder:
move /Y *.* Backup
We are trying to exit the script completely if the ERRORLEVEL is not equal to 0 but it never work as expected. Please advise.

In the logs we can see errors like
Timeout detected. (control connection)
Connection failed.
which might not return as ERRORLEVEL other than 0 I assume?

Thanks and appreciate your help!

Reply with quote

Advertisement

ericcao
Joined:
Posts:
2
Location:
canada

Re: Script ERRORLEVEL not working as expexted

Thanks. Please see attached log. Client FTP server is constantly lost connection and it is not returning error code 1:
. 2025-07-31 02:17:54.795 --------------------------------------------------------------------------
. 2025-07-31 02:17:54.796 Connecting to ingest.example.ca ...
. 2025-07-31 02:18:09.808 Timeout detected. (control connection)
. 2025-07-31 02:18:09.808 Connection failed.
. 2025-07-31 02:22:54.810 --------------------------------------------------------------------------

Reply with quote

Advertisement

You can post new topics in this forum