FTP sync (download)

This script can be used to download all files from a dir on your ftp to a dir on your local harddrive. They will be synchronized and if everything is correctly downloaded they will be removed from ftp. A logfile will be written.

#!/bin/bash
 
#Endlessloop to sync
while true
do
 
#var Hostname
HOST='localhost'
 
#var Username
USER='root'
 
#Path to FTPLogfile
LOGPATH=/var/log/ftprsync.log
 
#Path to FTP data
FTPPATH=/var/ftp/
 
#Path to local directory
PATH=/var/textfiles/
 
#check if there are textfiles to sync
if ssh $USER@$HOST "ls $FTPPFAD*.txt" >/dev/null 2>&1
then
 
#if there are textfiles sync them to the localdir and remove them from FTP 
#log number of files, speed, which files... to the logfile. -q (quiet) only shows error in shell nothing else
rsync --remove-source-files --stats --progress --log-file=$LOGPATH -q ${USER}@${HOST}:$FTPPATH*.txt $PATH
fi
 
#short wait time -> less cpu usage
sleep 5
done