0

How to make lftp run in background all time and push any change made to a local folder to a folder on remote server. The normal reverse mirror command isn't working for all time and specific to changes. Basically I want to keep both the folders in sync. Thanks

8
  • 1
    Have you consider to run it via cron? Or to use rsync to minimize the traffic? Commented Feb 17, 2016 at 7:37
  • How to do with cron? Also rsync will not work with ftp Commented Feb 17, 2016 at 9:51
  • You can tunnel rsync via ssh. You can set in cron script, which ill run lftp (every 5 minutes for example) and exec command to upload files/directories Commented Feb 17, 2016 at 10:22
  • Can you post the code or link? Commented Feb 17, 2016 at 10:44
  • Here is example command to rsync via ssh local dir to remote dir: rsync -avz -e ssh /local/path user@remote-host:/remote/path Commented Feb 17, 2016 at 12:00

1 Answer 1

1

Use the mirror function and a cron to trigger it repeatedly.

Put this in a script (e.G. ~/push_to_server.sh):

cd [PATH_THAT_YOU_WANT_TO_COPY]
lftp -c "open [HOST] -u [USER],[PASSWORD]; mirror -R [PATH_ON_SERVER]"

You want to look up the '-e' and '-P' funcion of lftp mirror in your manual (man lftp) and might use them together with -R.

Now you activate that script every few minutes with cron. Run crontab -e and add:

*/5 * * * * ~/push_to_server.sh

That will start the script every 5 minutes (please do read man 5 crontab to understand what the 5 and the asterisks are actually doing before changing them). Be sure to point to the actual path of the script in case you moved it or running crontab as a different user.

If your ftp sync takes longer then 5 minutes (at peak times) you have to change the cron. Read man 5 crontab to learn how to do that.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .