Keep folders in sync automation

Advertisement

vavs
Joined:
Posts:
4

Keep folders in sync automation

I have a group of folders which hold reports for various department heads on my file server. I access this file server using WinSCP. There is a feature that allows me to keep local directories up to date. This works great while I am on WinSCP. What I really need to do is to check this once a day and make sure that the remote and local folders are synced. It appears that there is a powershell script running in the background which moves the files from remote to local servers. Can anyone point me in the right direction on how to do this whether WinSCP is running or not? If I have to have a version of the software running locally on the file server, let me know that also. I was excited about this working I am just curious as to how to keep it running if I am not on line.

Reply with quote

Advertisement

vavs
Joined:
Posts:
4

First shot at the problem

Here is what I have for the code and I believe I have over simplified things
open sftp://remotedba:123456@66.66.66.666/ -hostkey="ssh-rsa 2048 76:aa:aa:66:66:f6:ea:b6:94:d3:38:73:38:bd:67:bb"
 
# mv *.xlsx /Reports *.*
 
exit
 
# Execute the script using a command like:
# "C:\Program Files (x86)\WinSCP\WinSCP.exe" /log="C:\writable\path\to\log\WinSCP.log" /ini=nul /script="C:\path\to\script\script.txt"
I don't know how I have to identify the source folder and the destination folder. I have a source location of fs-1/fs-e/ETL and a location of K:/programinfo/reports.

Also, I am going to have ten different folders that I want to send from and to. Can I set it up to change the directories of the source and local files in succession like
cd fs-1/fs-e/ETC/pgm1
lcd k:/programinfo/reports/pgm1
mv *.xlsx /pgm1 *.*
 
cd fs-1/fs-e/ETC/pgm2
lcd k:/programinfo/reports/pgm2
mv *.xlsx /pgm1 *.*
Once I have this the only other question is how to run this every hour or once a day or on some set schedule?

Thanks in advance for the help.

Reply with quote

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

Re: First shot at the problem

You want get -delete, not the mv.
https://winscp.net/eng/docs/scriptcommand_get

Have WinSCP generate a full transfer code on Transfer Options dialog.
https://winscp.net/eng/docs/guide_automation#generating

And yes, your approach with the cd and lcd is correct. Alternatively, specify a full paths in get.

For scheduling, see:
Schedule file transfers (or synchronization) to FTP/SFTP server

Reply with quote

vavs
Joined:
Posts:
4

Re: First shot at the problem

Martin,

Here is my code revised with your suggestion;
open sftp://remotedba:123456@66.66.66.666/ -hostkey="ssh-rsa 2048 76:aa:aa:66:66:f6:ea:b6:94:d3:38:73:38:bd:67:bb"
 
get -delete *.xlsx /Reports *.*
 
exit
 
# Execute the script using a command like:
# "C:\Program Files (x86)\WinSCP\WinSCP.exe" /log="C:\writable\path\to\log\WinSCP.log" /ini=nul /script="C:\path\to\script\script.txt"
I have this in a text file in a folder that is accessible to me only when I use WinSCP. I would like to execute the get and delete as a step in a SQL Server 2012 Agent Job. Do I need to create a batch file and execute the batch file from the agent job? Has this been done before? I have about 10 different agent jobs that get called at various points within a day and week so syncing the folders based on a time of day is not as relevant as doing it after the agent job is run.

Please advise at your earliest convenience.

Reply with quote

Advertisement

vavs
Joined:
Posts:
4

One last problem

I have a batch file created for each of the folders that I want to keep in sync. Here is the rub. For some reason, the file that I get is being placed in the directory of where the batch file is being run from. So my get command is:
"get -delete ""//fs1/FS-E/ETL/Error Reports/MF FR/*.xlsx K:\Tracking System\Error Reports\MF FR\""" ^
This batch file is being run from my desktop and when I do that, the file is dropped there. When I run it from the location: K:\Tracking System\Error Reports\MF FR the file is dropped there. Right now I am running the batch files manually for each location. What I want to do is to schedule the runs but only if I can make sure that the files end up in the right place.
Is there something wrong with my syntax that would keep it from placing the files at K:\Tracking System\Error Reports\MF FR regardless of where the batch file resides? Do I need to do an lcd command to change to the K:\ drive?

Reply with quote

Advertisement

You can post new topics in this forum