How to Automatically Backup Your Web Server Files With WinSCP over FTP

WinSCPYou’ve heard it time and time again: back up your data. There are plenty of backup solutions, but nothing is better than an easy and free solution. So with a few lines of code and a very helpful program called WinSCP, we’re going to set up an automatic sync between your FTP server and your home computer.


  • An FTP server and access credentials
  • A Windows computer
  • A copy of WinSCP (Windows only)

Setting Up WinSCP

Once you've downloaded your copy of WinSCP, install it on your computer. It also wouldn't be a bad idea to start remembering your FTP address, username, and password while WinSCP is installing.

From the login screen, enter your host name (i.e., username, and password. You can use either FTP or SFTP, but be sure to change the port number the appropriate port your FTP host has provided you. Then click Save to save the profile. Open the profile to log into your FTP server. This will verify that you typed the right credentials in the profile.


Create the script

We’re going to create a simple script that logs into your FTP server, tells WinSCP where to download the missing files to on your computer, and then creates a log file that records FTP activity. Go ahead and open Notepad on your computer. Copy the following script template into Notepad:

option batch on
option confirm off
cd backups
option transfer binary
get /testremote* f:\backups\testlocal*
synchronize local f:\backups\testlocal testremote

WinSCP will answer all prompts negatively to avoid holding up the script. Then it will automatically overwrite files when prompted. It then logs into your FTP server using the profile we created earlier, changes directories (if needed), and transfers binary (as opposed to ASCII). Finally, it reads the remote FTP directory and transfers files to the specified local directory. For even more options, check out the official WinSCP scripting page.

Now before you modify or run this script, we suggest creating test directories on both the remote and local targets. The last thing you want is to accidentally wipe your FTP server without any backups. So create a directory on your computer called “testlocal” (we created it under f:\backups) and another called “testremote” on your FTP server (we created it at the root). Once you run the script and it executes successfully, save it as “sync.txt” to your computer (we saved ours in our testlocal folder).

Automating the script

Now you’re ready to automate the script. For this we can use Task Scheduler.


Click on Create Basic Task and follow the following screens. First insert a name for your task.


Select when you want to start the task.


Select Start a program in the next screen.


Now click on Browse... and find WinSCP executable file in your program folder.


Underneath, add

/console /script=f:\backup\sync.txt /log=f:\backup\log.txt 

to Add arguments. Be sure to change the arguments if your sync.txt is in a different location and if you want to generate the log file in a different location. Click Next.

So the task is created!

Add comment