I have a task for synchronizing a remote ftp folder to a local folder. At the remote site, that day’s folder is placed in the form of year_month_day and the local folder placed in the form of year/month/day .
I have to copy the current day’s folder everyday because previous days folders are deleted regularly. In the case of a failure for copying files, the script must continue copying where it left off. So i decided to use wget command, wrote a script for that and put it into the crontab. I hope this helps you in such cases.
Remote ftp site synchronization script:
#!/bin/bash
year=$(date +%Y)
month=$(date +%m)
day=$(date +%d)
remote_folder=$year’_'$month’_'$day
local_folder=<ROOT FOLDER>/$year/$month/$day/
user=<USERNAME>
pass=<PASSWORD>
address=<FTP ADDRESS>
log_file=’<LOG FOLDER>’$remote_folder’.log’
touch $log_file
wget --mirror -nH --cut-dirs=1 -P $local_folder -o $log_file 'ftp://'$user':'$pass@$address'/'$remote_folder
Comments
Post a Comment