Synchronize Script – Confirmation & External Commands

Advertisement

gsidhu
Joined:
Posts:
2

Synchronize Script – Confirmation & External Commands

Hi there, I am looking to get a little help with my WinSCP synchronize batch script. First, I am looking to have the script output a notification, whether the script has successfully synchronized files or returned an errorlevel 1. As you can see in the screenshot provided below, I am presently not receiving a success or unsuccessful message at the end of my script.

I would like to use this as a first going, after which I would like to incorporate email confirmations. Which leads me to my second question – is it possible to output which of files have been either synchronized or do not require synchronization, and have the output sent by email? Would XML logging be the most simplistic means? Any examples anyone can provided?

Third and lastly, would be possible to execute an external command after each file has been synchronized? Ie., I would like to run an unzip command if the file have been updated, and move the files to a separate directory.

Batch:
winscp.com /script="F:\Scripts\ScriptNotificationTest.txt" /log="F:\Scripts\FTPNotificationTestLog.txt"
if errorlevel 1 goto error
 
echo Synchronization Successful.
goto end
 
:error
echo Synchronization Failed.
 
end:

Script:

#Automatically abort script on errors
option batch abort
 
#Disable overwrite confirmations that conflict with the previous
option confirm off
 
#Connect to ******* server using existing login credentials
open *******
 
#Synchronize database releases
#Synchronize Test Zip
synchronize local -criteria=time -resumesupport=on -filemask="TestZipFile.zip" "F:\*******\Databases\Stage\Test\"
 
#Synchronize Test Zip 2
synchronize local -criteria=time -resumesupport=on -filemask="TestZipFile2.zip" "F:\*******\Databases\Stage\Test\"


Thanks! :)

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,517
Location:
Prague, Czechia

Re: Synchronize Script - Confirmation & External Commands

gsidhu wrote:

Hi there, I am looking to get a little help with my WinSCP synchronize batch script. First, I am looking to have the script output a notification, whether the script has successfully synchronized files or returned an errorlevel 1. As you can see in the screenshot provided below, I am presently not receiving a success or unsuccessful message at the end of my script.
You are missing exit command at the end of your script, so it never terminates.

I would like to use this as a first going, after which I would like to incorporate email confirmations. Which leads me to my second question – is it possible to output which of files have been either synchronized or do not require synchronization, and have the output sent by email? Would XML logging be the most simplistic means? Any examples anyone can provided?
Yes, XML logging is the way to go. Though there's no way to find files that do not need synchronization.

Third and lastly, would be possible to execute an external command after each file has been synchronized? Ie., I would like to run an unzip command if the file have been updated, and move the files to a separate directory.
Well, parse the XML log and call the external command for each synchronized file yourself.
For such a task, using WinSCP .NET assembly (e.g. from PowerShell) might be easier. See this example for a similar task:
Deleting remote files after successful remote to local synchronization

Reply with quote

Advertisement

You can post new topics in this forum