%ERRORLEVEL% is always 0
Hey, great, it actually works that way. So the problem is really the same as with a
Many thanks for your support.
for
loop...
Many thanks for your support.
for
loop...
for
, but I believe the issue is the same with if
)
WinSCP.com
(WinSCP-Portable V5.21.7) on a Windows Server 2019 Standard (64-bit OS, x64-based processor).
WinSCP.com
to upload specific files, if any, to an FTP server. That works so far.
%ERRORLEVEL%
is always 0, regardless of whether the connection to FTP was successful or not.
rem *** Set drive and directory for batch script execution...
d:
cd %HOME_DIR%
echo. >> %LOG_FILE%
echo ############################################# JOB START ############################################### >> %LOG_FILE%
echo %nowDATE% %nowTIME% >> %LOG_FILE%
echo ####################################################################################################### >> %LOG_FILE%
if exist %SEARCH_FILES% (
echo ******************************************************************************************************* >> %LOG_FILE%
echo Local files to upload found! Do upload to FTP server... >> %LOG_FILE%
echo ******************************************************************************************************* >> %LOG_FILE%
C:\Install\WinSCP-Portable\5.21.7\WinSCP.com /log=WinSCP_Log.log /ini=nul /script=FTP_ConnectionTest_Error.txt
echo ERRORLEVEL %ERRORLEVEL% >> %LOG_FILE%
if %ERRORLEVEL% equ 0 (
echo ******************************************************************************************************* >> %LOG_FILE%
echo Move local files to the backup directory..." >> %LOG_FILE%
echo ******************************************************************************************************* >> %LOG_FILE%
move /Y %HOME_DIR%\%SEARCH_FILES% %BACKUP_DIR% >> %LOG_FILE% 2>&1
) else goto JOB_ERROR
) else (
echo ------------------------------------------------------------------------------------------------------- >> %LOG_FILE%
echo No local files to upload! >> %LOG_FILE%
echo ------------------------------------------------------------------------------------------------------- >> %LOG_FILE%
)
goto JOB_END
:JOB_ERROR
echo xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx >> %LOG_FILE%
echo Error occurred! The job was canceled! Inform responsible users... >> %LOG_FILE%
echo xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx >> %LOG_FILE%
Powershell.exe -executionpolicy remotesigned -File SendWarningEMail.ps1
:JOB_END
echo ############################################# PROGRAM END ############################################# >> %LOG_FILE%
echo
echo off
%ERRORLEVEL%
and moves the target file to the backup
directory even if a connection to the FTP could not be established and we actually expect something other than 0 for %ERRORLEVEL%
. Here what we see in this log file:
############################################# JOB START ###############################################
14.02.2023 14:26:44.46
#######################################################################################################
*******************************************************************************************************
Local files to upload found! Do upload to FTP server...
*******************************************************************************************************
ERRORLEVEL 0
*******************************************************************************************************
*******************************************************************************************************
1 file(s) moved.
############################################# PROGRAM END #############################################
...
. 2023-02-14 14:26:44.713 --------------------------------------------------------------------------
< 2023-02-14 14:26:44.729 Script: Connecting to egFTP.com ...
. 2023-02-14 14:26:44.729 Connecting to egFTP.com ...
. 2023-02-14 14:26:54.756 Connection failed.
< 2023-02-14 14:26:54.756 Script: Connection failed.
< 2023-02-14 14:26:54.756 Connection failed.
%ERRORLEVEL%
, even if connection fails? What are we missing?