Check for psftp file upload error in batch file

2.1k Views Asked by At

I am trying to upload a file from Windows server to third party server (I do not know OS etc. of this) through windows batch script. I am using PSFTP to upload files. It was working since a long time but since yesterday while uploading files, I am getting 'Network error: connection timed out' and batch script file control is doing further steps after file uploading step.

My requirement is whenever there is a failure to upload a file through psftp command through batch script, system should not proceed further. It should stop executing further steps.

Please let me know how to do this in Windows batch scripting?

1

There are 1 best solutions below

0
Martin Prikryl On

psftp returns exit code 1 on error. So you just check the exit code and act accordingly.

To records errors, just redirect all psftp.exe output to a file.

psftp.exe -b script.txt > script.log 2>&1

if errorlevel 1 (
    echo Error
) else (
    echo Success
    rem Other commands to perform on success
)