FTP TUTORIALS & GUIDES

How to Automate Website Backups Using FTP Scripts

Learn how to automate website backups using secure SFTP scripts, WinSCP, curl, lftp, cron, or Windows Task Scheduler. Schedule recurring transfers of website files and databases, protect credentials, organize dated backup copies, monitor logs, verify file integrity, apply retention rules, and test recovery before an emergency.

Updated: June 20, 2026
By: RSH Web Editorial Staff

Hosting from $2.99/mo
  See Plans    Contact Us

Menu

How to Automate Website Backups Using FTP Scripts

Learn how to automate website backups with SFTP scripts, WinSCP, curl, lftp, cron, or Task Scheduler. Copy files and databases on a schedule, protect credentials, keep dated archives, watch logs, and test a restore before you need one.

Automate website backups using FTP and SFTP scripts

Backups

A backup job should collect website files and, for apps such as WordPress, a database dump. Then it should copy that archive off the same server. Prefer SFTP. Do not store live passwords in a plain FTP script. Automating File Transfers

Schedule

Daily or weekly so a copy exists before an update or failure.

Offsite

Keep copies on another machine or cloud target, not only in public_html.

Test restore

A backup that was never restored is unproven. Manual recovery

Prerequisites

  • SSH/SFTP access, or an FTP account if you must use FTPS. Create an FTP Account
  • A destination folder that is not the live site tree.
  • WinSCP (Windows) or sftp/lftp plus cron (Linux/macOS/cPanel).

What the job should do

1Dump the database if the site uses one.
2Archive the site files (exclude cache and the backup folder itself).
3Name the archive with a date, e.g. site-2026-09-19.tar.gz.
4Copy it off-server with SFTP (WinSCP script, sftp, or lftp).
5Delete old copies after your retention window (for example 7 or 14 days).

Built-in ftp.exe / ftp -inv scripts send the password in clear text. Use WinSCP SFTP or OpenSSH keys instead. Using SFTP with cPanel

Schedule

Linux / cPanel cron — daily at 02:00:

0 2 * * * /path/to/backup.sh

Windows — Task Scheduler → Create Basic Task → run the WinSCP script daily.

Where to store copies

Another server or workstation over SFTP
Cloud object storage (S3 and similar)
An external disk that is not always attached to the web server

Restore check

  1. Download one dated archive.
  2. Unpack it on a staging copy, not on the live site first.
  3. Import the database dump if one exists.
  4. Confirm the site loads. Then keep that process documented. Manual Website Recovery

Frequently Asked Questions

How often should I back up a WordPress site?

Daily is a practical rhythm for a busy store or a site that changes all day. Weekly can be enough for a small brochure site that rarely updates. Also take a manual copy before plugin, theme, or core updates. Keep more than one dated copy so a bad backup does not replace the only good one. Recovery steps are in manual website recovery with FTP.

Does an FTP backup include the database?

Not by itself. FTP or SFTP copies files such as themes, plugins, uploads, and wp-config.php. WordPress posts and settings live in MySQL. Export the database in cPanel or include a dump in the same dated folder as the file archive. A files-only copy cannot rebuild the site alone. WordPress file work is covered in managing WordPress with FTP.

Can I automate backups without an FTP client window?

Yes. WinSCP scripts, cron plus sftp, or a cPanel backup tool can run unattended. Hosting backups and plugins such as UpdraftPlus are simpler if you do not want scripts. Scripts give more control over folders and destinations. General automation is in automating file transfers.

Should backup scripts use SFTP instead of FTP?

Yes when SSH is available. A scheduled job should not send the password in plain FTP. Use SFTP with a key, or FTPS for a regular extra FTP account. Do not store the secret in public_html. Protocol choices are in FTP vs SFTP vs FTPS and using SFTP with cPanel.

Where should I store the backup copies?

Keep at least one copy off the same server. Options include a local disk, another FTP/SFTP host, or cloud storage. A backup that lives only in public_html can vanish with the site. Use dated filenames and delete old copies on a retention plan so the disk does not fill. Create a limited login with an FTP account in cPanel.

What should I do if a scheduled backup fails?

Run the script by hand and read the log. Check hostname, protocol, quota, folder permissions, and whether the extra FTP user can see the path. Set a notification or review the log the next morning until the job is reliable. Do not assume silence means success. Connection checks are in FTP troubleshooting.

How do I restore from an FTP backup?

Download the dated archive, confirm it opens, then upload the files into the correct document root. Import the matching database dump if the site uses MySQL. Test on a staging folder when you can. File Explorer is a weak restore tool for large sites; use FileZilla or WinSCP. See WinSCP setup.

Is a dedicated backup FTP account safer than the main cPanel user?

Yes. Give the job its own account and, when possible, a folder that only holds backup archives. Do not put the primary cPanel password in a script. Prefer SFTP keys if SSH is on. More hosting articles are on the blog index.

Tweet  Share  Pin  Email

Add Comment

* Required information
Drag & drop images (max 3)

Comments

No comments yet. Be the first!

From the minds of our master copywriters

RSH Web Services is a leading web hosting provider with the most reliable, secure and fast service at affordable prices. We serve small businesses, large businesses and everything in-between. Our goal is to bring you the best value for your money with all of our website packages