Topic "How do I read success/failure in batch?"

Author Message
Sokonomi
[View user's profile]

Joined: 2015-04-26
Posts: 3
I currently have this script to upload a queue to a tablet;

Code:
@echo off
set LOG=%CD%\log.txt
set REMOTE_PATH=/Removable/MicroSD/
echo %date:~-4,4%/%date:~-7,2%/%date:~-10,2% %time:~0,8% QUEUE START >> %LOG%

:LOOP
set /p FILE= < "PPlist.txt"
IF "%FILE%" neq "" (
   echo %date:~-4,4%/%date:~-7,2%/%date:~-10,2% %time:~0,8% UPLOAD ATTEMPT : %FILE% >> %LOG%
   "C:\Program Files (x86)\WinSCP\winscp.com" /command ^
      "option batch abort" ^
      "option confirm off" ^
      "open ftp://xxx:xxx@xxx.xxx.xxx.xxx:xxxx" ^
      "put ""%FILE%"" %REMOTE_PATH%" ^
      "exit"
      IF %ERRORLEVEL% == 0 (
         echo %date:~-4,4%/%date:~-7,2%/%date:~-10,2% %time:~0,8% UPLOAD SUCCESS : %FILE% >> %LOG%
         more /E +1 "PPlist.txt" > "PPlist.txt.new"
         move /y "PPlist.txt.new" "PPlist.txt"
      ) ELSE echo %date:~-4,4%/%date:~-7,2%/%date:~-10,2% %time:~0,8% UPLOAD FAILURE : %FILE% >> %LOG%
      goto LOOP
) ELSE (
   echo %date:~-4,4%/%date:~-7,2%/%date:~-10,2% %time:~0,8% QUEUE COMPLETE >> %LOG%
   exit
)

But its behaving a bit strange.
It seems that when the destination has run out of space,
winscp still exits with errorlevel 0 the first time it loops around.
It does print "Error transferring file" before exiting though.
Am I doing it wrong?
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
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 can mark the attachment as private.
Sokonomi
[View user's profile]

Joined: 2015-04-26
Posts: 3
Ive attached the log you requested.

I suppose the one line of most importance is
Code:
. 2015-05-07 13:45:57.587 Script: Exit code: 1


My hypothesis; WinSCP sets exit code to 1 but doesn't exit,
it gets itself stuck in a loop retrying the transfer instead.

Did I use the wrong command parameters for it to exit upon failure?
log.txt (10.74 KB) [Download]

Description: Snippet of failed instance.

martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
Sokonomi wrote:
My hypothesis; WinSCP sets exit code to 1 but doesn't exit,
it gets itself stuck in a loop retrying the transfer instead.

You wrote before that WinSCP exits with code 0. So how does that go along with new hypothesis that it does not exit at all?

The log indicates that WinSCP behaves as expected.
Sokonomi
[View user's profile]

Joined: 2015-04-26
Posts: 3
Then why does it exit with exitcode 0 the first time around even though it failed to upload?

Because either the loop that is happening is staying within winscp,
or the loop is happening because the batch code is getting the wrong exit code.
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
Sokonomi wrote:
Then why does it exit with exitcode 0 the first time around even though it failed to upload?

Because either the loop that is happening is staying within winscp,
or the loop is happening because the batch code is getting the wrong exit code.

Application does NOT have an exit code when it does not exit.
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