For a long time, FTP (File Transfer Protocol) has been the go-to method for many developers to upload code to servers. However, FTP’s inherent limitations—such as slow transfer speeds for large numbers of small files and lack of intelligent synchronization—make it highly inefficient for modern development workflows.
In this article, we’ll introduce Rsync, a powerful and versatile terminal-based utility that is significantly faster and more reliable than FTP for deploying code.
Why Rsync is Superior to FTP
The primary advantage of Rsync over FTP is its delta transfer algorithm. Instead of re-uploading every file from scratch, Rsync compares the local and remote versions and only transfers the differences (the bits that have actually changed). This makes subsequent deployments incredibly fast.
Additionally, Rsync offers built-in compression during transfer, which further reduces bandwidth usage and speeds up the process, especially over slower network connections.
Basic Rsync Command Usage
Deploying a WordPress site or any other project with Rsync is typically done via a single command in your terminal. Here is a standard example:
rsync -avz --delete --exclude=.git* --exclude=node_modules/ --exclude=/wp-content/uploads/ /path/to/local/wordpress/ user@host:/path/to/remote/wordpress/
Let’s break down the flags used above:
-a(archive): Preserves permissions, ownerships, and timestamps.-v(verbose): Shows the progress and files being transferred.-z(compress): Compresses data during the transfer.--delete: Deletes files on the remote server that have been deleted locally, keeping the two locations perfectly in sync.--exclude: Allows you to skip specific files or directories (like Git history or heavy upload folders) that don’t need to be part of the deployment.
Managing Exclusions with a File
If your project has many files to exclude, your command line can become quite long and unwieldy. A cleaner approach is to list all excluded paths in a separate file, such as rsync-excludes.txt, and reference it in your command.
rsync -avz --delete --exclude-from=rsync-excludes.txt /path/to/local/wordpress/ user@host:/path/to/remote/wordpress/
Example rsync-excludes.txt:
.git*
node_modules
/wp-content/uploads/
/wp-content/upgrade/
/wp-content/debug.log
/wp-content/advanced-cache.php
/wp-content/object-cache.php
Note that the paths in the exclude file are relative to the root of the directory being synchronized. Using a leading slash (/) ensures the exclusion only applies to the root level, whereas omitting it would exclude matching files in any subdirectory.
A Smarter Way to Deploy
While moving from a GUI-based FTP client to a command-line tool like Rsync might seem intimidating at first, the efficiency gains are undeniable. Once you become comfortable with Rsync, you’ll find that your deployments are not only faster but also much more reliable, especially when dealing with large codebases over inconsistent networks. This investment in your workflow is one that will pay off significantly in the long run.
