Topic "success notification on errorlevel 0"

Author Message
mariad

Guest


I have a batch file that runs a winscp command. After the winscp command is run, i check for errorlevel - 0 means call 'PROCESS_SUCCESS' notification email, else call 'PROCESS_ERROR' notification email. I have noticed that whether the winscp command exited successfully or not, it always call the PROCESS_SUCCESS! Am I capturing the wrong ERRORLEVEL here for success/failure? I know it is failing because I am seeing a permission denied failure in the logs.

Here is part of the batch script running the winscp:

:WINSCP_SFTP_SCRIPT
for /f "tokens=*" %%z in (list.txt) do (
cd "%soucedir%"
set file=%%z
winscp.com /console /script=script.txt /log=ftp.log /parameter %%z %sourcedir%
if ERRORLEVEL 0 (
call :PROCESS_SUCCESS
) else (
call :PROCESS_ERROR
)
)
pause
*******************************

Here is what is in script.txt


option batch abort
option confirm off
open XXXX_XXXXXXXX@XXX.XXXX.com -hostkey="ssh-dss blah blah"
lcd "%2%"
put %1%
close
exit

*******************************

Winscp 5.1.1 on Windows Server 2008 R2 Enterprise Service Pack 1 (64bit OS). SFTP Protocol.

******************************
I want to be able to send success/failure emails. For example, I got this error below but it seems like it is evaluating to ERRORLEVEL 0 no matter what!

< 2014-05-29 13:26:49.058 Status code: 3, Message: 1372932, Server: Permission denied, Language: en
* 2014-05-29 13:26:49.058 (ETerminal) Permission denied.
* 2014-05-29 13:26:49.058 Error code: 3
* 2014-05-29 13:26:49.058 Error message from server (en): Permission denied
* 2014-05-29 13:26:49.058 Request code: 4
. 2014-05-29 13:26:49.059 Asking user:
. 2014-05-29 13:26:49.059 Cannot close remote file 'prdnssivr101_NEXTGEN_OSR_05282014.zip'. ("Permission denied.
. 2014-05-29 13:26:49.059 Error code: 3
. 2014-05-29 13:26:49.059 Error message from server (en): Permission denied
. 2014-05-29 13:26:49.059 Request code: 4")
< 2014-05-29 13:26:49.059 Script: Cannot close remote file 'prdnssivr101_NEXTGEN_OSR_05282014.zip'.
< 2014-05-29 13:26:49.060 Script: Permission denied.
< 2014-05-29 13:26:49.060 Error code: 3
< 2014-05-29 13:26:49.060 Error message from server (en): Permission denied
< 2014-05-29 13:26:49.060 Request code: 4
* 2014-05-29 13:26:49.061 (EScpSkipFile) Cannot close remote file 'prdnssivr101_NEXTGEN_OSR_05282014.zip'.
* 2014-05-29 13:26:49.061 Permission denied.
* 2014-05-29 13:26:49.061 Error code: 3
* 2014-05-29 13:26:49.061 Error message from server (en): Permission denied
* 2014-05-29 13:26:49.061 Request code: 4
. 2014-05-29 13:26:49.061 Script: Failed
. 2014-05-29 13:26:49.062 Script: Exit code: 1
. 2014-05-29 13:26:49.062 Closing connection.
. 2014-05-29 13:26:49.062 Sending special code: 12
. 2014-05-29 13:26:49.062 Sent EOF message
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
The if ERRORLEVEL 0 means "if exit code is 0 or greater", what is always true.

That's why all the examples on this site have the condition reversed, such as:
http://winscp.net/eng/docs/guide_automation#results

Also read if /? help.
MariaD

Guest


prikryl wrote:
The if ERRORLEVEL 0 means "if exit code is 0 or greater", what is always true.

That's why all the examples on this site have the condition reversed, such as:
http://winscp.net/eng/docs/guide_automation#results

Also read if /? help.


////////////////

Got it! Thank you very much! Smile
mariad

Guest


Hello again!

So I am revisiting my script and remembered your advise from my last inquiry. I did that and now even the FTP part don't launch at all anymore.

**********************

:WINSCP_SFTP_SCRIPT
for /f "tokens=*" %%z in (list.txt) do (
cd "%soucedir%"
set file=%%z
winscp.com /console /script=script.txt /log=ftp.log /parameter %%z %sourcedir%
if NOT ERRORLEVEL 0 call :PROCESS_ERROR
call :PROCESS_SUCCESS
)
pause
***********************

What am I missing here? Thanks in advance!!


What am I
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
You haven't changed anything the WinSCP call itself. So I do not see, how the new problem can be related.
Anyway the "even the FTP part don't launch" hardly gives enough information for anyone to help you. Please provide more information. For example the log.
_________________
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