Post a reply

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)


Topic review


Thanks for your feedback. I would still like to see a log file of your original setup though. Because the change you've done should not have an effect on the exit code.

Hi Martin.

The tests I've done are very promising, the problem was the /console "PROFILE" call.
When I put it as "open PROFILE" into the script, it works ok and brings back exactly what I expect, with the version 4.4.0.

Thank you very much for your help

I wish you a merry christmas!


Hi Martin.

Thank you for your fast response. I'll check it out as suggested and come back then.


Re: Errorlevel not as expected

First, your use of WinSCP is not supported. You should not combine scripting and opening session using command-line argument. You should use open command from the script.

Second, you should really upgrade.

Anyway, to investigate your problem, just turn on logging using /log=log_path switch. If the problem is not obvious, please attach a full log file here.

Errorlevel not as expected


I use the version 4.4.0, and there I found a behaviour, which is not transparent to me.
I test this version since I have the exact documented problem in Bug #953 in Version 4.3.2.

Here is what I do:

C:\temp> E:\FTP_Tools\WinSCP\ /console "PROFILE_NAME"
winscp> option batch abort
winscp> option confirm off
winscp> option transfer ASCII
winscp> cd /
winscp> get filename_exist.csv
winscp> close
winscp> exit
C:\temp> echo %errorlevel%

This means, the session is opened correctly, the file is found and downloaded and returns an errorlevel of "0"
Now, the "get line" is changed to "get filename_does_not_exist.csv", after finsishing the winscp executable, the errorlevel returned is "1".
This is exactly, what I expect, success returns a "0", error returns a "1".

In the next step, I write all the commands into a file called E:\FTP_Scripts\0099_wscp.scri instead of supplying them interactively,
the script-file looks like this:

option batch abort
option confirm off
option transfer ASCII
cd /
get filename_exist.csv

and then I start the command with
C:\temp> E:\FTP_Tools\WinSCP\ /console "PROFILE_NAME" /script=E:\FTP_Scripts\0099_wscp.scri

After finishing, I also want to read the errorlevel with
C:\temp> echo %errorlevel%

Regardless of a successful end or not (file exists or not), I get the errorlevel "1" in every situation.

I have tried a lot of things, like
- set retcode=%errorlevel% and echo Returncode %retcode% in order to make sure that the value of the errorlevel is not overwritten
- try all winscp-options that could make sense or not, like option batch abort, option batch on, etc.
- put it all in a bat and start this with and without the call command.
- start the command from within the WinSCP-Folder or not
- . . .

Where am I wrong? Is this maybe a bug in 4.4.0?

Thank you very much for your help.