分类:
2008-06-14 22:26:19
# program: auto
#
clear
plan() # 显示任意多个字符函数
{
z=$1
c=$2
m=1
while [ "$m" -le "$z" ]
do
echo "$c\c"
m=`expr $m + 1`
done
}
echo "\033[3;10H远程主机名[或IP]:\c"
read host
if [ "$host" = "" ];then
exit
fi
echo "\033[4;10H远程机用户名:\c"
read user
echo "\033[5;10H远地用户口令:\c"
echo "\033[2;8;8m\c"
read password
setcolor -n
echo "\033[6;10H命令[get|put]:\c"
read getput
if [ "$getput" != "get" ] && [ "$getput" != "put" ];then
tput bel
echo "\033[12;10H无效的操作命令...\c"
read err
exit
fi
echo "\033[7;10H$getput文件名:\c" # 可以带路径不要加通配符
read bdfile
echo "\033[11;10H正在检验网络及用户...\c"
## ftp出错提示,想不出好办法 :-(
ftp -n $host<yd.tmp 2>/dev/null
user $user $password
dir $bdfile
bye
!
grep "Not connected" yd.tmp >/dev/null
if [ $? -eq 0 ];then
tput bel
echo "\033[12;10H主机未联接,网络是否通畅或主机名错?...\c"
read err
exit
fi
grep "Login failed" yd.tmp >/dev/null
if [ $? -eq 0 ];then
tput bel
echo "\033[12;10H失败,用户名或口令是否有误?...\c"
read err
exit
fi
if [ "$getput" = "get" ];then
bpatch=`pwd`
file=$bdfile
awk '{print $9}' yd.tmp | grep "$bdfile" >/dev/null
if [ $? -eq 0 ];then
count=`awk '{print $5}' yd.tmp` # 取远地文件大小
else
tput bel
echo "\033[12;10H找不到远地文件名...\c"
read err
exit
fi
bpatch=`pwd`
file=`echo $bdfile | awk -F"/" '{print $NF}'`
ypatch=`echo $bdfile | sed 's/'$file'$//g'`
if [ "$ypatch" = "" ];then
ypatch="."
fi
else
# 取本地文件大小
ls -l $bdfile >/dev/null 2>/dev/null
if [ $? -ne 0 ];then
tput bel
echo "\033[12;10H找不到本地文件名...\c"
read err
exit
fi
file=`echo $bdfile | awk -F"/" '{print $NF}'`
bpatch=`echo $bdfile | sed 's/'$file'$//g'`
ypatch="."
count=`ls -l $bdfile | awk '{print $5}'` # 取本地文件大小
fi
# 自动ftp函数,默认为binary
autoftp()
{
ftp -n $host<dmp.tmp 2>/dev/null
user $user $password
bin
hash
lcd $bpatch
cd $ypatch
$getput $file
bye
END
}
autoftp & # 放在后台执行
tput civis
echo "\033[10;10H文件大小:$count"
echo "\033[11;6H┌─────────────────────────┐"
echo "\033[12;6H│ │"
echo "\033[13;6H└─────────────────────────┘"
kcou=`echo "sclae=2;$count/1024"|bc` # 计算文件有多少传输块
if [ `echo $kcou | sed 's/^[0-9]*.//g'` = "00" ];then
kcou=`echo $kcou | sed 's/...$//g'`
else
kcou=`echo $kcou+1 |bc | sed 's/...$//g'`
fi
cou=0
while true ##[ "$cou" -le "$kcou" ]
do
j=`echo "scale=2;$cou/$kcou*100"|bc|sed 's/.00$//g'` # 计算进度
n=`grep '\#' dmp.tmp` # 取文件传输块
cou=`echo -n $n|wc -c`
if [ "$j" = "100" ];then
ycsize=$count
else
ycsize=`echo $cou*1024|bc`
fi
echo "\033[10;41H已完成:$ycsize "
s=`expr $j \/ 2`
echo "\033[12;8H\c"
plan $s "\033[7m \033[2;7;0m" # 画进度条
echo "\033[11;32H"$j"%" # 显示百分比
if [ "$j" = "100" ];then
echo
tput cnorm
tput bel
rm dmp.tmp
echo "\033[14;10HOK Press any key... \c"
read ok
exit
fi
done