Script that should give exit code of 1 does not
WinSCP returns exit code 1, when any command is interrupted due to an error or any prompt is answered Abort (even automatically in batch mode). Otherwise it returns the exit code 0.
However, I run a PowerShell script that runs a winscp.com script and gives the output below. Errors are generated but the error checking in PowerShell does not get an error code of 1.
Is it possible that the successful uploads in the ftp script are overwriting the error codes from the earlier uploads that fail, even though it's one script?
PowerShell script portion:
winscp.com /script=$working_dir\$ftp_script /ini=$working_dir\$ftp_ini
if ($LASTEXITCODE -ne 0)
...send message...
Log output (with one word edited with an 'x' added because it's getting caught in your spam filter):
C:\Program Files (x86)\Business Objects\BusinessObjects Enterprise 12.0\Data\procSched\REPSYS09.ProgramJobServer\procprogramf9c718233b6ee0>powershell \\FILER2.co.cuny.adlan\boe_admin\REPORTINGPROD\Supplemxentary_Files\CUNY_Alert\cuny_alert.ps1
batch on
confirm off
Searching for host...
Connecting to host...
Authenticating...
Using username "CUNY".
Authenticating with pre-entered password.
Authenticated.
Starting the session...
Reading remote directory...
Session started.
Active session: [1] CUNY@ftp.nyalert.gov
\\FILER2.co.cuny.adlan\boe_admin\REPORTINGPROD\Supplemxentary_Files\CUNY_Alert\GroupTemplateId.csv | 0 KiB | 0.0 KiB/s | binary | 0%
Cannot overwrite remote file '/users/cuny/GroupTemplateId.csv'.
Press 'Delete' to delete the file and create new one instead of overwriting it.
General failure (server should provide error description).
Error code: 4
Error message from server: Failed to open local file
Request code: 3
(D)elete, (A)bort, (R)etry, (S)kip, Ski(p) all: Abort
\\FILER2.co.cuny.adlan\boe_admin\REPORTINGPROD\Supplemxentary_Files\CUNY_Alert\UserTemplateId.csv | 0 KiB | 0.0 KiB/s | binary | 0%
Cannot overwrite remote file '/users/cuny/UserTemplateId.csv'.
Press 'Delete' to delete the file and create new one instead of overwriting it.
General failure (server should provide error description).
Error code: 4
Error message from server: Failed to open local file
Request code: 3
(D)elete, (A)bort, (R)etry, (S)kip, Ski(p) all: Abort
\\FILER2.co.cuny.adlan\boe_admin\REPORTINGPROD\Supplemxentary_Files\CUNY_Alert\UserTemplateUpdateId.csv | 39 KiB | 69.3 KiB/s | binary | 100%
\\FILER2.co.cuny.adlan\boe_admin\REPORTINGPROD\Supplemxentary_Files\CUNY_Alert\DeleteUserId.csv | 0 KiB | 0.0 KiB/s | binary | 100%
\\FILER2.co.cuny.adlan\boe_admin\REPORTINGPROD\Supplemxentary_Files\CUNY_Alert\DeleteGroupId.csv | 5 KiB | 3.7 KiB/s | binary | 100%
Session 'CUNY@ftp.nyalert.gov' closed.
No session.
Here is the ftp script with the password and key edited.
# Preferences in winscp.exe are set to
# Set permissions is off
# Preserve timestamp is off
# Automatically answer all prompts negatively not to stall
# the script on errors
option batch on
# Disable overwrite confirmations that conflict with the previous
option confirm off
# Connect using a password
open CUNY:xxxxx@ftp.nyalert.gov -hostkey="xxxxxxx"
# Upload the file to current working directory
PUT %working_dir%\GroupTemplateId.csv
PUT %working_dir%\UserTemplateId.csv
# If %PUT_CHANGE% equals "PUT", the following files are uploaded.
# If %PUT_CHANGE% equals "#", the following are commented out.
%PUT_CHANGE% %working_dir%\UserTemplateUpdateId.csv
%PUT_CHANGE% %working_dir%\DeleteUserId.csv
%PUT_CHANGE% %working_dir%\DeleteGroupId.csv
# Disconnect
close
# Exit WinSCP
exit