I need to keep my web page synchronized with a local directory.
A very effective tool is lftp
, which I use with the script:
#!/bin/bash
HOST='ftp.remote.it'
USER='username'
PASS='password'
TARGETFOLDER='.'
BASEFOLDER='/home/my/folder/'
SOURCEFOLDER='_site'
cd $BASEFOLDER || exit
lftp -f "
open $HOST
user $USER $PASS
mirror --reverse --only-newer --ignore-time --delete \
--verbose $SOURCEFOLDER $TARGETFOLDER
bye
"
By using the option --delete
I make sure that when I delete a file locally, the corresponding file is deleted remotely too. However, on the website I put additionaly stuff which does not come from the local website and which I do not want to delete when I make an update (the effect of --delete
is that everything on the remote folder and subfolders not existing in the local folder is deleted).
A solution could be keeping a list of the files existing in the local folder at the last update; then, by comparing the local directory with the list, I can obtain a list of deleted files. In this way, the mirroring of the local website comes in two steps: first I delete the files on the website corresponding to the locally deleted files, then I upload all updated and new files using lftp
without the option --delete
.
However, to my surprise, I have found no way to make lftp (or any other ftp client) delete a list of files remotely taking the list from a file.