Topic "Keep folders in sync automation"

Author Message
vavs
[View user's profile]

Joined: 2016-09-29
Posts: 4
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.
Advertisements
vavs
[View user's profile]

Joined: 2016-09-29
Posts: 4
Here is what I have for the code and I believe I have over simplified things
Code:

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

Code:

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.
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25015
Location: Prague, Czechia
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/ui_generateurl

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

For scheduling, see:
https://winscp.net/eng/docs/guide_schedule
vavs
[View user's profile]

Joined: 2016-09-29
Posts: 4
Martin,

Here is my code revised with your suggestion;

[code/]
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"
[/code]

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.
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25015
Location: Prague, Czechia
Yes, you can store the command to a batch file.

But as it is a single command only, you can also use it, as is, in the Task.

Again, see https://winscp.net/eng/docs/guide_schedule
vavs
[View user's profile]

Joined: 2016-09-29
Posts: 4
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:
[code/]
"get -delete ""//fs1/FS-E/ETL/Error Reports/MF FR/*.xlsx K:\Tracking System\Error Reports\MF FR\""" ^
[/code]
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?
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25015
Location: Prague, Czechia
You have the quotes wrong.

Correct syntax is:

"get -delete ""//fs1/FS-E/ETL/Error Reports/MF FR/*.xlsx"" ""K:\Tracking System\Error Reports\MF FR\""" ^

See https://winscp.net/eng/docs/commandline#syntax
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