由于mget命令下载速度太慢,就写了个脚本,可以用来进行多线程多(单)文件同步下载,速度比原来得快不少。供大家参考,欢迎转帖。
[code:1]
#!/bin/bash
# PARM1: SOURCE DIRECTORY ON REMOTE HOST
# PARM2: HOST ADDRESS
# PARM3: DESTINATION PATH TO SAVE DOWNLOADED FILES
# PARM4: DYNAMICALLY CREATED SHELL FILE TO RETRIVE REMOTE FILES WITH "PGET" COMMAND
REMOTEPATH=$1
HOSTADDR=$2
DESTPATH=$3
DYNAFILE=$4
# test if REMOTEPATH parameter is specified
if [ "$REMOTEPATH" = "" ]; then
echo "Parameter: REMOTEPATH was not specified."
exit 1
fi
# test if HOSTADDR parameter is specified
if [ "$HOSTADDR" = "" ]; then
HOSTADDR=ftp.abc.com
echo "Parameter: HOSTADDR was not specified, use default hostname: $HOSTADDR."
fi
# test if REMOTEPATH parameter is specified
if [ "$DESTPATH" = "" ]; then
echo "Parameter: DESTPATH was not specified."
exit 1
fi
# make sure $REMOTEPATH $DESTPATH do not end with '/'
#
DESTPATH=`echo $DESTPATH | sed 's/\/$//g'`
REMOTEPATH=`echo $REMOTEPATH | sed 's/\/$//g'`
# test if destination path exists
if [ ! -d $DESTPATH ]; then
# if Destination Path: $DESTPATH does not exist, it will be created automatically.
mkdir $DESTPATH
if [ `echo $?` = "1" ]; then
echo "Cannot create directory: $DESTPATH."
exit 1
fi
fi
# test if destination path is writable
if [ ! -w $DESTPATH ]; then
echo "Destination Path: $DESTPATH is not writable."
exit 1
fi
# use traceroute to test connectivity
traceroute $HOSTADDR > $tracelog 2>&1
grep "unkown host" $tracelog >/dev/null 2>&1
if [ `echo $?` = "0" ]; then
echo "Host: $HOSTADDR is not reachable."
exit 1
fi
# retrieve file list
lftp $HOSTADDR<<FTPCMD
cd $REMOTEPATH
lcd $DESTPATH
nlist > $DYNAFILE
quit
FTPCMD
# multi file multi connections downloading, uncomment next line
# sed 's/^./pget &/g' $DYNAFILE | sed 's/$/& \&/g' > $DYNAFILE
#single file multi connections downloading, comment next line for multi file multi connections downloading
sed 's/^./pget &/g' $DYNAFILE | cat > $DYNAFILE