%ERRORLEVEL% is always 0

Advertisement

Tina_ls
Guest

%ERRORLEVEL% is always 0

Hello
I have a problem.
I'm using the below script.
"F:\Tools\WinSCP_51710\WinSCP.com" ^
  /log="F:\Tools\WinSCP_51710\WinSCP_51710.log" /ini=nul ^
  /command ^
    "option batch abort" ^
    "open ftp://%ftp_username%:%ftp_password%@%FTP_IP% -explicit -certificate=*" ^
    "ls "%FTP_DIR_LIVE%"" ^
    "exit"
 
set WINSCP_RESULT=%ERRORLEVEL%
if %WINSCP_RESULT% equ 0 (
  echo Success
) else (
  echo Error
)
ECHO ERRORLEVEL %ERRORLEVEL%
But %WINSCP_RESULT% is always 0 even if the log remains "Script: Exit code: 1".
I want to get the real error code.
Please advise.
Thank you.

err.png

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
35,996
Location:
Prague, Czechia

Re: %ERRORLEVEL% is always 0

Your script looks good. There's probably some tiny syntax problem that you post does not show.
Check this: https://winscp.net/eng/docs/faq_batch_file#newline_escaping

What do you get if you put ECHO ERRORLEVEL %ERRORLEVEL% right after the "exit" line?

This is wrong: "ls "%FTP_DIR_LIVE%"" it should be:
    "ls ""%FTP_DIR_LIVE%""" ^
What do you get if you try this?
winscp.com /command "foo"
echo %ERRORLEVEL%

Reply with quote

Advertisement

You can post new topics in this forum