Post a reply

Before posting, please read how to report bug or request support effectively.

Bug reports without an attached log file are usually useless.

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

bobrico62

Re: Error Code always 0

Thank you Martin, this did it!
martin

Re: Error Code always 0

You need:
    "option failonnomatch on" ^
    "put -nopreservetime -nopermissions D:\aews\maintenance.application\export\*.fil" ^

See https://winscp.net/eng/docs/scriptcommand_option#failonnomatch

Other thing is that the %ERRORLEVEL% in your WinSCP commandline will be expanded by Windows command interpreter before it even runs WinSCP. You you will always get 0 there.
To get the actual value, you need to print the value after WinSCP finishes:
set WINSCP_RESULT=%ERRORLEVEL%
ECHO ERRORLEVEL %WINSCP_RESULT%
bobrico62

Hi Martin, any idea what I am doing wrong?

I have tried batch file method and a native WinSCP script with no luck. Whenever files are not in the source DIR and transfers fail,, it still comes back as 0 (success)
bobrico62

Error Code always 0

I have a simple script that transfers files no issues but success or failure it shows as success. Would appreciate any guidance.

The batch file:
@echo off
 
"D:\temp\WinSCP\WinSCP.com" ^
  /log="D:\temp\winscp\WinSCP.log" /ini=nul ^
  /command ^
    "open sftp://CM111XXXSI:XxXXxXXX@QAFILEXMIT:10088/ -hostkey=""ssh-rsa 2048 *****************************************"" -privatekey=""D:\certificate\e*********.ppk"" -passphrase=""***********"" -rawsettings AuthKI=0 GSSAPIFwdTGT=1 KEX=""rsa,ecdh,dh-gex-sha1,dh-group14-sha1,WARN,dh-group1-sha1""" ^
    "put -nopreservetime -nopermissions D:\aews\maintenance.application\export\*.fil" ^
    "ECHO ERRORLEVEL %ERRORLEVEL%" ^
    "exit"
 
set WINSCP_RESULT=%ERRORLEVEL%
if %WINSCP_RESULT% equ 0 (
  echo Success
) else (
  echo Error
)
 
exit /b %WINSCP_RESULT%


Here's the output with 0 files in the local dir:
d:\escrow\jobs>filetransfer

Searching for host...
Connecting to host...
Authenticating...
Using username "CM111XXXSI".
Authenticating with public key "*******".
Further authentication required
Authenticating with pre-entered password.
Authenticated.
Starting the session...
Session started.
Active session: [1] CM111XXXSI@*********
No file matching '*.fil' found.
ERRORLEVEL 0
Success