WinSCP: Simply copy to remote Linux server

WinSCP: Simply copy to remote Linux server

Overview

I wanted a simple method to regularly copy some files from my Windows PC to my file server via SSH.
I already used WinSCP to manage files on file server, so just wanted a way to automate a backup similar to rsync.

This is a brief tutorial on how to create a simple Winscp script to copy files from a Windows PC to a remote Linux server

Solution

1. First download and install WinSCP.
2. Create a new text document `script.txt` in `C:\Program Files\WinSCP` and open it in notepad.
3. Customise these examples to suit requirements and save the file.

  •     This example will synchronise a local folder to a remote folder.
open sftp://username:[email protected]
synchronize remote -preservetime -delete "c:\local\folder" "/home/user/remotefolder"
exit
  •     This example that will syncronise a remote folder to a local folder.
open sftp://username:[email protected]
synchronize local -preservetime -delete "c:\local\folder" "/home/user/remotefolder" 
exit

4. Open another new text document and enter the following.

cd c:\Program Files\WinSCP
winscp.exe /console /script=script.txt
exit

5. Save the file as remotecopy.bat in any location.

5. Run the file to test and the files will now copy to the remote location.

6. Add a scheduled task to run at a set time.

There are various other options you can use depending on requirements however this is a simple example to get started.

For further information you can use the official documentation.
http://winscp.net/eng/docs/scripting

Leave a Reply

Be the First to Comment!

Leave a Reply

wpDiscuz