1

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?

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
saikiran
  • 71
  • 2
  • 8

1 Answers1

2

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
)
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992