[Note] #Synchronizing Remote FTP folder to Local Drive #Linux #FTP #Sync

Krishnendu Paul

Oct 6, 2020 1 min read


Sometimes you need to watch a FTP directory for new files and periodically downloading the. Even if you can create a script to use ftp command and trigger it through crontab - I also suggest to use LFTP or NCFTP , though it is not a regular command. LFTP having a bunch of functions and it is really advance. NCFTP is more simplistic.

1) LFTP

To watch a directory and download new files in 30 seconds interval, use following command

lftp -c "set ssl:verify-certificate no; set net:max-retries 0; set net:reconnect-interval-base 30; set net:reconnect-interval-multiplier 1 && open -u USER,PASSWORD SERVER_NAME_OR_IP && mirror -n Local_Folder Remote_Folder"

You can run it inside screen . It will connect per 30 seconds intervals and download if any new files exits without any common error.

2) NCFTP
Another easy but working option is using ncftp. It is not in default installation and mostly you can install it using apt repo.

sudo apt-get install ncftp

then use screen or nohup to run command in background so even if you are disconnected from terminal, it works.

Use it in following way

watch -n 30 -x ncftpget -u 'USER' -p 'PASSWORD' FTPSERVER LOCALFOLDER REMOTEFOLDER

So, it will run ncftpget per 30 seconds to download the new file. Then disconnect from the screen terminal and it will run in background.

Saving it for future use to I don't need to remember it and it may can help you ?!

😃



Great! You've successfully subscribed.
Great! Next, complete checkout for full access.
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.