Why is WinSCP returning non zero exit code?

When checking results of your script you may encounter non zero exit code, indicating error, for reason that may not be obvious to you.

Sometimes the exit code indicates error even, when you consider outcome of the script successful. This is usually caused by a syntax error in the script command that is not essential for the overall script task.

Inspecting Script Output

If you are able to reproduce the problem, when running the script in console window, check the script output for any errors.

In the example below you can see that although the connection and file transfer finishes successfully, the attempt to set script option confirm to yes (instead of valid on) is the reason, why script exits with code 1 nevertheless.

Searching for host...
Connecting to host...
Authenticating...
Using username "martin".
Authenticated.
Starting the session...
Reading remote directory...
Session started.
Active session: [1] martin@example.com
Unknown value 'yes' of option 'confirm'.
index.php            |          5 KiB |  115,6 KiB/s | binary | 100%

Inspecting Log File

If you are not able to reproduce the problem, when running the script in console window, at least try to enable session logging, e.g. using /log command-line parameter. Once the script finishes, search the generated log file for message “Script: Failed”, which should immediately follow the cause of the problem.

...
. 2010-11-27 20:45:09.849 Getting current directory name.
. 2010-11-27 20:45:09.849 Startup conversation with host finished.
< 2010-11-27 20:45:09.849 Script: Active session: [1] martin@example.com
> 2010-11-27 20:45:09.849 Script: option confirm yes
< 2010-11-27 20:45:09.849 Script: Unknown value 'yes' of option 'confirm'.
. 2010-11-27 20:45:09.850 Script: Failed
> 2010-11-27 20:45:09.850 Script: put index.php
. 2010-11-27 20:45:09.850 Copying 1 files/directories to remote directory "/home/martin/public_html"
...
. 2010-11-27 20:46:12.738 Script: Exit code: 1

Note that the log (being associated with a session) would not record error that occurs before a session starts (such as when the failing option command would precede the open command). In this case use the previous approach of inspecting script output.

 
  faq_exit_code.txt · Last modified: 29 Nov 2012 by prikryl
 

Search Documentation

This page

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

Associations

Kyplex Cloud Security Seal - Click for Verification

Site design by Black Gate