- 论坛徽章:
- 0
|
ftp上目录A的文件不定期地在更新,我想要一个脚本能够自动对比ftp上的目录A和本地目录B,然后把不同部分的文件下载到目录B,可以实现吗?
谢谢!
在论坛上学到的方法:
#!/bin/ksh
FTP=ftpaddress
LOCALDIR=localdir
FTPDIR=ftpdir
USER=username
PASSWORD=password
#Delete old filelist file
if test -a /$LOCALDIR/filelist; then
rm $LOCALDIR/filelist
fi
#get filelist from ftp
cd $LOCALDIR
ftp -i -n << !
open $FTP
user $USER $PASSWORD
ascii
passive
cd $FTPDIR
ls * filelist
bye
!
#check to see if there's new file available to download
#if yes, download the file
for file in `cat $LOCALDIR/filelist`
do
if [ -a $LOCALDIR/$file ]; then
echo "$file exist!";
else
echo "$file does not exist, downloading..."
ftp -i -n << !
open $FTP
user $USER $PASSWORD
ascii
passive
cd $FTPDIR
get $file
quit
!
fi
done
[ 本帖最后由 gtaww 于 2006-6-9 06:57 编辑 ] |
|