Script that should give exit code of 1 does not

Advertisement

jullman
Joined:
Posts:
5

Script that should give exit code of 1 does not

According to the Scripting section of this website,
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

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,461
Location:
Prague, Czechia

Re: Script that should give exit code of 1 does not

Please post a complete log file (using /log= command line paramter). Make sure you are using 4.3.8.

Reply with quote

jullman
Joined:
Posts:
5

problems with debugging

I can't duplicate the problem. It seems to have been some kind of file glitch that I cannot determine and have no way to duplicate.

I tried forcing a problem by renaming one of the files I am PUTTING, so it doesn't match the name in the PUT statement. This resulted in:
"File or folder '\\FILER2.co.cuny.adlan\boe_admin\REPORTINGdev\Supplemenxtary_Files\CUNY_Alert\GroupTemplateIdx.csv' does not exist.
System Error. Code: 2."

This error WAS picked up by the exit code.

The initial error I wrote about, that was NOT picked up by the exit code is:
"\\FILER2.co.cuny.adlan\boe_admin\REPORTINGPROD\Supplemenxtary_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"

This seems to be an error on the remote system.

I don't know how to go forward if I can't duplicate the situation. But this is a production system and I need to know that I am capturing all errors. Have you any ideas for me?

Thanks.

Please ignore purposeful typo on the word "Sup...ment."

Reply with quote

martin
Site Admin
martin avatar

Re: problems with debugging

I have simulated the "Cannot overwrite remote" error and I got the exit code 1 as expected.
Please keep logging on (using /log switch) and post the log, if it ever happens again.
Also make sure you are using the latest version of WinSCP.

Reply with quote

Advertisement

jullman

Next steps

I will turn the logging on. I hope there is a way to keep it from growing too large (or I'll have to script something). If you have any tips of how to recreate the error, please let me know. I don't have access to the destination machine, but I do have others I could try with.

Thanks

Reply with quote

jullman
Joined:
Posts:
5

Re: Next steps

martin wrote:

You can use the !D!T pattern in log path to have every session logged into a separate file, so that you can remove the logs of successful sessions.
https://winscp.net/eng/docs/ui_pref_logging

For recreating the error: I had to change to code to simulate it. So no, I do not have any tip for you to recrete it yourself.

If I change the script from "option batch on" to "option batch abort" do you think it will be likely to pass the error to LASTEXITCODE? Do you see any disadvantage to changing it? I understand that PUT statements after an error will not be executed.

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
41,461
Location:
Prague, Czechia

Re: Next steps

jullman wrote:

If I change the script from "option batch on" to "option batch abort" do you think it will be likely to pass the error to LASTEXITCODE?
It should not make a difference.

Do you see any disadvantage to changing it?
I generaly prefer the "abort" option.

I understand that PUT statements after an error will not be executed.
Correct.

Reply with quote

Advertisement

You can post new topics in this forum