Exit Code = 1

Advertisement

RabbitChaser
Joined:
Posts:
2

Exit Code = 1

WinSCP.exe version 4.1.6, running on Windows Server 2003 R2 Standard Edition.

We use WinSCP.exe in a scheduled job to automatically transfer requests to one of our vendors. The scheduled job runs this batch file.

@echo off
WinSCP.exe /script=%1 %2
echo %ERRORLEVEL%

Where %1 is the name of the script file and %2 is the login credentials. A typical script file might look like this.

option batch on
option confirm off
option batch abort
cd inbound
put "Q:\WORK\UNDWDEPT\MVR\Daily\2009\10 - October\Requests\TC00002B4332"
close
exit

The ERRORLEVEL (exit code of WinSCP.exe) is read from the batch file. If it's 0 then we mark the file as sent, otherwise we try sending the file again later. This has been working fine for months, until last Friday. Then we suddenly started receiving exit codes of 1. Upon further investigation we found that the files were in fact making it to the remote server correctly, even though we were getting a non-zero exit code.

Any idea why the sudden change from 0 to 1 in the exit code? Could it be due to a change on the receiving system?

Does the 1 mean anything specific?

How can I reliably tell if the transfer was successful or not?

Thanks.

Reply with quote

Advertisement

RabbitChaser
Joined:
Posts:
2

Cause Found

I think I've discovered the problem. The file server has a lock on WinSCP.ini. The close statement causes WinSCP to write to the ini file. When this fails, it throws an error and return "1". Since the close happens after the put, the file is actually on the remote server.

I can get the current ini file unlocked, but I'd like to protect against this happening again. Here are two ideas I have. Please feel free to comment if you think one is better than the other or have any suggestions.

1. Put "option batch abort" right before the "put" command and "option batch continue" right before the "close" command. That way it will only abort and exit with a "1" if there is an error during transmission.

OR

2. Start each session with the /ini= parameter, using a unique file name each time. After the batch file runs WinSCP.exe, it can delete the unique ini file.

Thanks

Reply with quote

Kedar
Guest

Getting Exit Code 1 while closing the session

Hi,

I am also having similar problem while closing the session. I am just getting one file from remote directory using below script. File was copied, but it had problems while closing the session.

I checked the Exit Code of the script in batch file. It was 1.

Here is my Script:
\\\\
# Automatically answer all prompts negatively not to stall
# the script on errors
option batch abort
option echo off

# Disable overwrite confirmations that conflict with the previous
option confirm off

# Connect using a password
# open user:password@example.com
# Connect

open sftp://%USERNAME%:%PASSWORD%@%HOST%:22

# Change remote directory
cd %SOURCE_DIR%

# Force binary mode transfer
option transfer binary

# check flag file
get xxx.flg

# Disconnect
close
# Exit WinSCP
exit

\\\\\

This script was running fine, but today following problem occurred.

Log file:

batch abort
echo off
confirm off
Searching for host...
Connecting to host...
Authenticating...
Using username "s3m_system".
Authenticating with pre-entered password.
Authenticated.
Starting the session...
Reading remote directory...
Session started.
Active session: [1] user@xxx.xxx.xxx.xx
/bdata/exp/check_img
transfer binary
xxx.flg | 0 KiB | 0.0 KiB/s | binary | 0%
Host has not answered for more than 15 seconds. Still waiting...
Warning: Aborting this operation will close connection!
(A)bort: Abort
Terminated by user.
(A)bort, (R)econnect (5 s): Reconnect
Searching for host...
Connecting to host...
Authenticating...
Host has not answered for more than 15 seconds. Still waiting...
Warning: Aborting this operation will close connection!
(A)bort: Abort
Terminated by user.
Authentication failed.
(A)bort, (R)econnect (5 s): Reconnect
Searching for host...
Connecting to host...
Authenticating...
Using username "user".
Authenticating with pre-entered password.
Authenticated.
Starting the session...
Reading remote directory...
Session started.
check status code "1"
/////

As per my understanding, file gets copied, but while closing the session, connection to host was lost. It has tried few times, and got successfully connected, but returned the exit code as 1, while command 'close'.

I also checked that, my WINSCP.INI file updated everytime after closing the session, but when this error occurred, INI file was not updated.

How can I avoid this from happening in future ?

Thanks in Advance,
Kedar

Reply with quote

martin
Site Admin
martin avatar

Re: Getting Exit Code 1 while closing the session

Why do you think there was a problem when closing a session?

Reply with quote

Advertisement

Kedar
Guest

First of all, Thank you Martin for the reply :) ,

I think that because, after getting the file, I only did two steps

1. Close the session
2. Exit the script

& as per logs, File was transferred successfully,

//////

Session started.
Active session: [1] user@xxx.xxx.xxx.xx
/bdata/exp/check_img
transfer binary
xxx.flg | 0 KiB | 0.0 KiB/s | binary | 0%

//////

but after that, while closing the session, problem has been occurred.

otherwise, it would have given the message as session closed, like this
Session user@xxx.xxx.xxx.xx' closed, which I can always find in my logs, when there is normal execution.

I also found that, WINSCP.INI file was not updated during this execution.

Could you please guide me on it ?


Thanks in Advance,
Kedar

Reply with quote

martin
Site Admin
martin avatar

OK, I believe that actually WinSCP returns 1 because there was an error while transferring the file (connection was lost). WinSCP was able to reconnect and resume the transfer, but it still issues the 1 as a warning.

Reply with quote

Kedar
Guest

Thanks Martin :)

So, what do you suggest in this case ? I am confused, because File got transferred,
but returned Exit Code as 1, & I was interrupting my remaining Program if Error Code is 1.

Reply with quote

Advertisement

You can post new topics in this forum