分类: LINUX
2015-06-18 19:55:25
#!/bin/bash
#
# 遍历本地ldir目录和文件,批量上传到ftp的rdir
#
if [ $# -eq 2 ]; then
ldir=$1
rdir=$2
else
echo "Usage: $0 ldir[/tmp/Temp] rdir[/20150617]"
exit
fi
IP='114.xx.63.xx'
U='xxlcomcn'
P='dxx123lc'
#### first mput 1 level dir's file
echo "Begin mput $ldir/ file"
ftp -n<
open $IP
user $U $P
binary
hash
mkdir $rdir
cd $rdir
lcd $ldir
prompt
mput *
close
bye
!
function mput_subdir() {
local ldir rdir
ldir=$1
rdir=$2
echo "Begin mput $ldir to $rdir"
ftp -n<
open $IP
user $U $P
binary
hash
mkdir $rdir
cd $rdir
lcd $ldir
prompt
mput *
close
bye
!
}
function scandir() {
local cur_dir parent_dir workdir
workdir=$1
cd ${workdir}
if [ ${workdir} = "/" ]
then
cur_dir=""
else
cur_dir=$(pwd)
fi
for dirlist in $(ls ${cur_dir})
do
if test -d ${dirlist};then
echo ${cur_dir}/${dirlist}
mput_subdir "${cur_dir}/${dirlist}" "${rdir}/${dirlist}"
cd ${dirlist}
scandir ${cur_dir}/${dirlist}
cd ..
#else
# echo ${cur_dir}/${dirlist}
fi
done
}
scandir $ldir