WinSCP will abort the script by default, if a command fails.
For sending an email on error, see:
https://winscp.net/eng/docs/script_email
For sending an email on error, see:
https://winscp.net/eng/docs/script_email
REM Don't show any command line stuff, by turning echo off.
@ECHO OFF
REM Generate a script file to use for WinSCP, this avoids a second text file from needing to exist.
echo option batch abort > test.tmp
echo option confirm off >> test.tmp
echo open sftp://username:password@sftpsite >> test.tmp
echo cd "/SFTPDIRECTORY" >> test.tmp
echo option transfer binary >> test.tmp
echo GET *.FILENAMENJ* "S:\stagingdirectory\" >> test.tmp
echo rm *.FILENAMENJ* >> test.tmp
echo close >> test.tmp
echo exit >> test.tmp
REM Run WinSCP, use the temp script created above, and set log file location.
"C:\Program Files\WINSCP\WinSCP.com" /console /script=test.tmp /log="C:\LOCALDIRECTORY\TestBackup.log"
"C:\LOCALDIRECTORY\TestPut.bat" -- (THIS IS ANOTHER SCRIPT TO PUT THE FILES TO ANOTHER SFTP.. LISTING BELOW)
REM See if script completed
if errorlevel 1 goto error
cls
echo SUCCESSFULLY DOWNLOADED TESTFILES
goto end
:error
cls
echo ERROR DOWNLOADING TESTT FILES, CHECK LOG: 'C:\LOCALDIRECTORY\TestBackup.log'
:end
close
testput.bat
that the prior script is calling
REM Don't show any command line stuff, by turning echo off.
@ECHO OFF
REM Generate a script file to use for WinSCP, this avoids a second text file from needing to exist.
echo option batch abort > testputscript.tmp
echo option confirm off >> testputscript.tmp
echo open sftp://username:password@SFTPTOPUTFILES >> testputscript.tmp
echo option transfer binary >> testputscript.tmp
echo cd /DIRECTORYTOPUTFILES >> testputscript.tmp
echo put S:\stagingdirectory\*.FILENAMENJ* >> testputscript.tmp
echo close >> testputscript.tmp
echo exit >> testputscript.tmp
REM Run WinSCP, use the temp script created above, and set log file location.
"C:\Program Files\WINSCP\WinSCP.com" /console /script=testputscript.tmp /log="C:\LOCALDIRECTORY\testPutBackup.log"
MOVE \stagingdirectory\*.FILENAMENJ* \stagingdirectory\Archive
REM See if script completed
if errorlevel 1 goto error
cls
echo SUCCESSFULLY UPLOADED TESTPUT FILES
goto end
:error
cls
echo ERROR UPLOADING TEST FILES, CHECK LOG: 'C:\LOCADIRECTORY\TestPutBackup.log'
:end
close