Rsync and LFTP are wonderful tools for synchronizing files. Here are various examples.
NOTE: If certificate errors prevent you from connecting to a trusted server, you can disable these errors permanently:
echo “set ssl:verify-certificate false” >> ~/.lftprc
To connect to a server and mirror it to a local directory:
lftp productionserver.com user email@example.com ls cd public_html lcd /var/www/devsite/ mirror
To mirror local directory to remote:
To exclude a folder:
mirror --exclude somefolder/
Rsync is great as it can securely synchronize data over ssh, also it is very efficient as it only transfers changed blocks and bytes of files.
rsync options source destination
- -v : verbose
- -r : copies data recursively (but don’t preserve timestamps and permission while transferring data
- -a : archive mode, archive mode allows copying files recursively and it also preserves symbolic links, file permissions, user & group ownerships and timestamps
- -z : compress file data
- -h : human-readable, output numbers in a human-readable format
- --exclude : items to exclude, eg.
- --include : items to include
- --delete : use with extreme caution! This will delete files and folders at the destination if they do not exist at the source.
- --max-size : maximum size of files to transfer, eg.
- --bwlimit : bandwidth limit, eg.
- --dry-run : shows the output of your rsync command but does not actually manipulate any files
To use rsync over SSH to sync a remote site to local devsite:
rsync -avz -e ssh firstname.lastname@example.org:/var/www/productionsite/public_html /var/www/devsite