Results 1 to 1 of 1
#Author:Wise Huang
#email:hnsnet@online.sh.cn
#I come from China and this message was submitted in China, but the language is Chinese, maybe someone can not read, so I sumbit this english version ...
- 01-23-2008 #1Just Joined!
- Join Date
- Jan 2008
- Posts
- 1
A full script of ftp upload files
#Author:Wise Huang
#email:hnsnet@online.sh.cn
#I come from China and this message was submitted in China, but the language is Chinese, maybe someone can not read, so I sumbit this english version here.
#Here is the shell script how to ftp send 3 files in a batch and make sure they was uploaded sucessful.
#These files looks like following: 2008-01-01 08:00:01.000, ctn 2008-01-01 08:00:01.txt, all 2008-01-01 08:00:01.txt
#Fistly, we must find the file *.000 in local server, if no this file, don't send this batch
#We suppose the local folder is /home/ers/out
#And the remote folder is /
===========Please copy following script if you need=======
#/bin/sh
ftpusername='guest1'
ftppassword='password123'
#backup the files which will sent
cp /home/samba/ers/out/*.* /home/samba/ers/bak
#In order to avoide the conflict, move the files to a temp folder named "buffer" firstly
mv /home/samba/ers/out/*.* /home/samba/ers/buffer
cd /home/samba/ers/buffer
#get the file *.000, it is a flg file. e.g 2008-01-01 08:00:01.000
ls -rt *.000 > /home/samba/ers/localfile.lst
sed -e "s/.000//g" /home/samba/ers/localfile.lst > /home/samba/ers/localfile.txt
localfile=`head -1 /home/samba/ers/localfile.txt`
ctrfile="ctr "$localfile".txt"
allfile="all "$localfile".txt"
markfile=$localfile".000"
#end of get file name which will be sent.
#put three files in one batch
ftpresults=`ftp -vn<<!
open 220.1.1.2
user $ftpusername $ftppassword
binary
prompt off
cd /buffer
lcd /home/samba/ers/buffer
put "$ctrfile"
put "$allfile"
put "$markfile"
lcd /home/samba/ers
!
`
#Analysis the ftp results, output the ftp results to a log file firstly.
echo $ftpresults > /home/ftp.log
#As the ftp result have no return, so split this log to some lines. use "tr", it is very impotant.
#Then get the key words "bytes sent in"
ftp_success=`echo $ftpresults|tr "." "\n"|grep "bytes sent in"|wc -l`
# Above sentance mean add a return if met ".", and find "bytes sent in", then count the words "bytes sent in"
echo $ftp_success
#If we got three times "bytes sent in", it means ftp three files sucessful.
if [ $ftp_success -eq 3 ] ; then
ftp -n<<!
open 220.1.1.2
user $ftpusername $ftppassword
binary
prompt on
rename /buffer/"$allfile" /"$allfile"
rename /buffer/"$ctrfile" /"$ctrfile"
rename /buffer/"$markfile" /"$markfile"
!
#Rename is a ftp command what move remote files
rm -f /home/samba/ers/buffer/"$ctrfile"
rm -f /home/samba/ers/buffer/"$allfile"
rm -f /home/samba/ers/buffer/"$markfile"
rm -f /home/samba/ers/filelist.txt
fi
========
unset remotefile
unset ctrfile
unset allfile
unset markfile
exit 0


Reply With Quote