Selective mirroring over FTP

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.


Solution 1:

The following is untested and comes from reading the doc and adapting it to what rsync does.

According to the man page, mirror has the following options:

        -i RX,   --include=RX               include matching files
        -x RX,   --exclude=RX               exclude matching files
        -I GP,   --include-glob=GP          include matching files
        -X GP,   --exclude-glob=GP          exclude matching files
                 --include-rx-from=FILE
                 --exclude-rx-from=FILE
                 --include-glob-from=FILE
                 --exclude-glob-from=FILE   load include/exclude patterns from the file, one per
                                            line

Use them. You can keep a list of files, folders or globs (wildcards) you don't want deleted remotely on your local machine and just tell lftp to ignore everything that's in there, which implicitly will not delete it on the remote side (unless you use the --delete-excluded switch ...). The stuff should not need to be present locally (if it behaves like rsync in that regard).