Not sure what is missing in this windows batch and winscp commands, I am struggling to see the ERRORLEVEL value apart from 0 even in negative scenario where winscp command returns errorcode greater than 0.
See the below example.
I have given incorrect username and password and expecting the winscp program to fill ERRORLEVEL greater than 0.
ECHO Connecting WinSCP...
SET TMPLOC_WINSCP="C:\Program Files\WinSCP\winscp.com"
set FILE_TO_GET=TEST.txt
%TMPLOC_WINSCP% /command ^
"option batch abort" ^
"option confirm off" ^
"open ""DEVCONN""" ^
"get %FILE_TO_GET%" ^
"exit"
ECHO ERRORLEVEL error code is... %ERRORLEVEL%
IF %ERRORLEVEL% NEQ 0 GOTO ERROR_WINSCP
echo File downloaded successfully...
:ERROR_WINSCP
echo Error occured...%ERRORLEVEL%
GOTO END
and console log is...
Connecting WinSCP...
batch abort
confirm off
Searching for host...
Connecting to host...
Authenticating...
Using username "XYZ".
Authenticating with pre-entered password.
Access denied.
Connection has been unexpectedly closed. Server sent command exit status 0.
Authentication log (see session log for details):
Using username "XYZ".
Access denied.
Authentication failed.
ERRORLEVEL error code is... 0
File downloaded successfully...
If the above result is expected, then what are the ways to identify when a connection establishment has failed and accordingly script can execute fallback commands..
I am using using winscp 4.3 in windows 8 OS. Please let me know if i am missing anything here....
/log=path\winscp.logto command-line and share the log with us.