HOST='ftp.YOUR FTP HOST.com'
USER='YOUR FTP USER NAME'
PASS='YOUR FTP PASSWORD'
lftp -f “
user $USER $PASS
mirror –delete –exclude cache –verbose $SOURCEFOLDER $TARGETFOLDER
Save the above script in your home folder as backup.sh. run with ./backup.sh from that folder. you need lftp installed: sudo apt-get install lftp
lftp offers many parameters, here i'll explain some of the most useful ones :
–reverse : Indicates that you want to update your remote folder. if you want to update your local folder then you should remove this option and also swap values of TARGETFOLDER and SOURCEFOLDER variables
–delete : It tells lftp that you want to remove all the files/folders that no longer exist on source folder
–use-cache : If you're about to sync very large number of files, this option can speed up things a lot. It does not have any effect the first time but in the next sessions it uses local cache instead of scanning the remote server
–exclude : Sometimes there are folder/files on both source and target folders that have nothing to do with the mirroring, using this option we can tell lftp to ignore this sort of files