By virtual of the file transferring tool ‘WinSCP'[download link], we can schedule a task to tier a specified directory path to a remote server directory server path automatically and periodically.
The magic is it frees your hand to do the duplicated steps day by day, for example manually uploading files steps by steps to log server with slow speed. With the help of the automated script, it will run at background without manual intervention.
In this section, I only refer how to set schedule in the recent Windows version, you could access to the official website to know other Windows versions or other platforms:
Scheduling on Windows 10, Windows 8 and Windows 7
To add new scheduled task:
- Go to Control Panel:
- Windows 10 and Windows 8.1: Right click Windows Startbutton and select Control Panel.
- Windows 7: Go to Windows Start Menu > Control Panel.
- In Control Panel, go to System and Security > Administrative Tools > Schedule Tasks.
- In the Task Scheduler menu go to Action > Create Basic Task.
- Give your task a name and click Next.
- Choose when the task should be run and click Next.
- For task action, select Start a programand click Next.
- Browse for exeexecutable.
- In Add argumentsadd appropriate WinSCP command-line parameters to execute the scripting commands you need (typically you will use /script or /command parameters).
- You should also add /logparameter to turn on session logging to file.
- The resulting arguments may look like:
/log=c:\path\winscp.log /command “open sftp://user:firstname.lastname@example.org/” “put d:\examplefile.txt /home/user/” “exit”
Note that the command-line parameter /console was not specified, what makes exe not show the console window, not to disturb you while you are using your workstation.
You can have WinSCP generate the command-line template for you.
- If your script uses local paths relative to the script path or WinSCP executable path, specify the respective path in Start in
- When done, click Next, review your options and confirm with Finish.
### Copy local file to Server using sftp protocol and only upload to modified files
C:\temp\WinSCP.exe /log=C:\temp\winscp.log /command "open sftp://username:password@FQDN -hostkey=*" "put -neweronly -preservetime C:\temp\files\* /yourpath/" "exit" /console /synchronize /keepuptodate
### Server side running crontab to avoid the target location removed accidentally by other people
$ crontab -l
0 0 * * * /bin/mkdir /your/path
To be continued…