以下代码用于FTP传送文件,并判断文件是否传送成功
传送成功返回0,否则返回1
# FTPTrans $localdir $remotedir $filetoput
# Return 0 on seccuess, 1 on fail
FTPTrans()
{
localdir=$1
remotedir=$2
thefile=$3
echo << EOF >> $LOGFILE
********************FTP Commands********************
lftp -u $USER,$PASS ftp://$host
(Binary mode by default)
> cd $remotedir
> lcd $localdir
> put $thefile
> bye
********************FTP Commands********************
EOF
lftp -u $USER,$PASS ftp://$host << EOF >> ftp_session.$$ 2>&1
cd $remotedir
lcd $localdir
put $thefile
bye
EOF
# This can tell whether lftp is successed or not
ftpstatus=$?
eccho "--------------------FTP Status : ftpstatus --------------------" >> $LOGFILE
sed 's/^/> /' ftp_session.$$
failstatus=`egrep "(Access failed:) | (Access is denied) | (Name or service not known)" ftp_session.$$`
echo "---------------------FTP Session Log start----------------------" >> $LOGFILE
cat ftp_session.$$ >> $LOGFILE
if [ -n $failstatus ]
then
echo "FTP failed, check permissions" >> $LOGFILE
fi
eho "----------------------FTP Session Log end------------------------" >> $LOGFILE
rm -f ftp_session.$$
if [ $ftpstatus == 0 ]
then
return 0
else
return 1
fi
}