Is there a way to check for completed download and only move a bunch of files after completion?
Here is what I have. We have a SFTP that we download a list of files from. After the files are downloaded to a staging location, they then need to be FTP'ed over to another SFTP site and then moved to an archive folder within the staging directory (and also removed from the original SFTP site)
Here's the issue. The company wants to issue a "check", where the files do not get FTP'ed over or moved to an archive folder unless they are successfully downloaded in the first place. Is this possible to do? I already have the job writing to a log file, so I figured I could rely on what's within the log file to be able to do this. However, this does not seem to be what is wanted.
Also, is there a way to send an e-mail notification other than using sendmail?
To give you an idea of what we have:
-----------------
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
--------------
This is 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
Here's the issue. The company wants to issue a "check", where the files do not get FTP'ed over or moved to an archive folder unless they are successfully downloaded in the first place. Is this possible to do? I already have the job writing to a log file, so I figured I could rely on what's within the log file to be able to do this. However, this does not seem to be what is wanted.
Also, is there a way to send an e-mail notification other than using sendmail?
To give you an idea of what we have:
-----------------
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
--------------
This is 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