Topic "Error Level Not being returned?"

Author Message
BICKY1980
[View user's profile]

Joined: 2014-01-27
Posts: 6
I have a command which I execute using T-SQL. The command runs fine but the errorlevel does not get returned to SQL.

The command I am running is: (I am purposely specifying a file which does not exists to get the error code)

Code:
c:\winscp.com /console /command "option batch abort" "option confirm off" "open ftp://[hiddenFTPdetails]" "put c:\work\test3.txt" "exit" & ECHO errorcode=%ERRORLEVEL%


The following gets returned?

Code:
batch           abort     
confirm         off       
Connecting to ftp://[hiddenFTPdetails] ...
Connected with ftp://[hiddenFTPdetails] Waiting for welcome message...
Connected
Starting the session...
Reading remote directory...
Session started.
Active session: [1] ftp://[hiddenFTPdetails]
File or folder 'c:\work\test3.txt' does not exist.
System Error.  Code: 2.
The system cannot find the file specified
(A)bort, (R)etry, (S)kip, Ski(p) all: Abort
errorcode=0
NULL


As you can see the System Error code is being returned correctly but the errorlevel (System Error. Code: 2.) being read back to SQL is 0 (errorcode=0) - how do i echo the system error code

Please help

Thanks
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24512
Location: Prague, Czechia
Environment variables on one line (no matter if that line includes multiple commands using &) are resolved BEFORE that line is executed.
Try dir nonexisting & echo %ERRORLEVEL%. You will also get 0.
_________________
Martin Prikryl
BICKY1980
[View user's profile]

Joined: 2014-01-27
Posts: 6
Does this mean I need to pass the commands within a script file
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24512
Location: Prague, Czechia
First, you cannot get the "System Error 2" back via WinSCP exit code. WinSCP return always 0 or 1.
I just wanted to point out that your test with & ECHO errorcode=%ERRORLEVEL% is irrelevant.

Please attach a full log file showing the problem (using the latest version of WinSCP).

To generate log file, use /log=path_to_log_file command-line argument. Submit the log with your post as an attachment. Note that passwords and passphrases not stored in the log. You may want to remove other data you consider sensitive though, such as host names, IP addresses, account names or file names (unless they are relevant to the problem). If you do not want to post the log publicly, you may email it to me. You will find my address (if you log in) in my forum profile. Please include link back to this topic in your email. Also note in this topic that you have emailed the log.
BICKY1980
[View user's profile]

Joined: 2014-01-27
Posts: 6
Thanks for the clarification.

What I need to be able to do is run winscp via the command line and if anything fails for whatever reason I want to be informed of it. Having a code returned would be ideal which is why ideally I was wanting the system error code as this specified the exact problem. I have been using XP_cmdshell on SQL Server which runs it fine but when I encounter a problem I need winscp to inform me.

The command I am running is:

Code:
c:\winscp.com /console /command "option batch abort" "option confirm off" "open ftp://[hiddenFTPdetails]" "put c:\work\test3.txt" "exit"


If I could still make use of the return code what would the correct syntax be? (Log file attached if this helps??)
testlog.txt (4.83 KB) [Download]

Description: (none)

martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24512
Location: Prague, Czechia
I cannot support an ancient version of WinSCP you are using. Please upgrade to the latest version and post a log file using it (for session, where WinSCP fails).
_________________
Martin Prikryl
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License