Topic "Is there a way to check for completed download and only move a bunch of files after completion?"

Author Message
Hooba

Guest


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
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24993
Location: Prague, Czechia
You can use an XML log file to collect files that were initially downloaded and generate post-upload delete script based on that.
https://winscp.net/eng/docs/logging_xml

Though it would be easier to use PowerShell script using WinSCP .NET assembly.

This example is close to what you look for, except that you need two sessions and delete the files uploaded over the second session from the first session, instead of moving local files:
https://winscp.net/eng/docs/script_local_move_after_successful_upload

This example has also some code that you may reuse (for deleting the remote files):
https://winscp.net/eng/docs/library_example_delete_after_successful_download
Hooba

Guest


Ok, I misunderstood what exactly was needed. Apparently, they want a CHECK after EVERY action and for it to not continue on to the next action unless the prior one is successful. If it fails, then do something (such as send an e-mail or whatever we choose). Is there a way to do this after EVERY action?
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24993
Location: Prague, Czechia
WinSCP will abort the script by default, if a command fails.

For sending an email on error, see:
https://winscp.net/eng/docs/guide_automation#results
Hooba

Guest


prikryl wrote:
WinSCP will abort the script by default, if a command fails.

For sending an email on error, see:
https://winscp.net/eng/docs/guide_automation#results



Unfortunately, this is not good enough. They actually want to be able to see the "check" within the script to be convinced that it's happening. Thoughts?
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24993
Location: Prague, Czechia
What is "check that it's happening"?
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License