Since a while, I’ve been looking for a simple way to sync/mirror a local directory with an FTP directory. In this case, to update dickson.tf without going through FileZilla every time.
Turns out, there is a program for linux called lftp which will do just that, and quite easily.
The way I’ve done it is to create a script that will manage this, and launch it when I want to send an update:
#! /bin/bash echo "Updating example.com" HOST='ftp.example.com' USER='YourUser' PASS='YourPassword' TARGETFOLDER='/your/remote_dir' SOURCEFOLDER='/home/user/local_dir' lftp -f " open $HOST user $USER $PASS mirror --reverse \ # reverse mirror = put files --newer-only # only files that have been changed --delete \ # delete files that no longer exist --use-cache \ # can be faster --verbose \ --exclude-glob .* \ # exclude files that start with . $SOURCEFOLDER $TARGETFOLDER \ " echo "done"
This will sync all files from /home/user/local/dir towards /your/remote_dir of the remote server, creating a mirror copy.
You can then put this in a cron job to automatically update any changes every day:
or anything else you fancy.