Batch command with Log exclusion lost transfer errorlevel

Advertisement

SaveMeGoogle
Guest

Batch command with Log exclusion lost transfer errorlevel

I finally got this transfer code working which limits the data going into the logfile but it has the unfortunate side effect of FindStr replacing the errorlevel so I lose the ability to detect a failed upload or other issue.
Is there anyway to retain the WinSCP transfer errorlevel result and keep the findstr pipe? I wasn't able to find a way to suppress findstr from modifying the errorlevel.

COMMAND IN BATCH FILE
"C:\Applications\WinSCP\winscp.com" /command "option batch on" "option confirm off" " open SomeFTPSite -hostkey="*"" "lcd E:\WorkingFolder\Temp\" "put ""ABMC_*.txt"" ""/ftpfolder/fakefolder/""" "exit"| findstr /v "batch confirm failonnomatch In open Searching Connecting Authenticat Using Starting Session""
DATA SENT TO LOGFILE
Active session: [1] SomeFTPSite
E:\WorkingFolder\Temp
Using configured transfer settings different from factory defaults.
ABMC_xl201091ma |            0 B |    0.0 KB/s | binary |   0%
Cannot create remote file '/ftpfolder/fakefolder/ABMC_xl201091ma.txt'.
No such file or directory.
Error code: 2
Error message from server: No such file
(A)bort, (R)etry, (S)kip, Ski(p) all: Abort

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,276
Location:
Prague, Czechia

Re: Batch command with Log exclusion lost transfer errorlevel

You can redirect the output to a temporary file, process the exit code, and only then pipe the temporary file though the findstr:
winscp ... > %temp%\winscp.out
if errorlevel 1 ( echo error ) else ( echo success )
type %temp%\winscp.out | findstr ...
del %temp%\winscp.out

Reply with quote

SaveMeGoogle
Guest

Re: Batch command with Log exclusion lost transfer errorlevel

This is the first time on a coding site I have gotten a positive response, this is a wonderful community. Below is what I ended up with, my global downtime module is working and the logs still look great. This is part of a 2,250 automation script template that I created and this is the last item in the latest upgrade that was holding me back. Thank You Martin!

:MODULE_13_2_UPLOADFTP
   ECHO.& ECHO ░░░░░░░░░░░░░░░░░░░░░░ FTP UPLOAD %UploadCount% ░░░░░░░░░░░░░░ATTEMPT %AttemptsUpload%
   ECHO Copying %Filename% to {S}FTP %UploadConnection% at %UploadPath%
   REM ECHO %FTPCOMMAND2% "open %UploadConnection% -hostkey="*"" "lcd %TempPath%" "put ""%Filename%"" ""%UploadPath%""" "exit"
   %FTPCOMMAND2% "open %UploadConnection% -hostkey="*"" "lcd %TempPath%" "put ""%Filename%"" ""%UploadPath%""" "exit" > %DowntimeTemp%
   IF ERRORLEVEL 1 (SET "FTPERROR=1") ELSE (SET "FTPERROR=0")
   TYPE %DowntimeTemp%%FTPEXCLUSION%
   DEL "%DowntimeTemp%"
   ECHO Error level %FTPERROR%
   IF "%FTPERROR%" NEQ "0" GOTO :MODULE_13_5_UPLOADERROR
   ECHO FILE{S} UPLOADED SUCCESSFULLY
   ECHO %TODO2%             {%UploadCount%} Up FTP - [%UploadConnection%]
   GOTO :MODULE_13_4_UPLOADSUCCESS
   ECHO THIS SHOULDNT HAPPEN SOMETHING IS SETUP WRONG IN MODULE_13_2_UPLOADFTP& GOTO :MODULE_18_1_EXIT

Reply with quote

Advertisement

You can post new topics in this forum