ftp -i -n -v >${logFile} 2>&1 <<FTPFILE open ${ftpIp} user ${ftpUser} ${ftpPwd} cd ${ftpPath} lcd ${localPath} mget *.txt bye FTPFILE } # 检查FTP获取文件是否成功 FtpCheck() { logFile=$1 fileName=$2 grep "Not Connected"${logFile} if [ $? -eq 0 ]; then Log "登录FTP服务器[${ftpIp}]失败, 地址错误或网络不通, 请检查..." Log "日志信息:\n`cat ${logFile}`" exit 1 fi
grep "Login failed"${logFile} if [ $? -eq 0 ]; then Log "登录FTP服务器[${ftpIp}]失败, 用户名或密码错误, 请检查..." Log "日志信息:\n`cat ${logFile}`" exit 1 fi
grep "Failed to change directory"${logFile} if [ $? -eq 0 ]; then Log "切换FTP目录[${ftpPath}]失败, 请检查..." Log "日志信息:\n`cat ${logFile}`" exit 1 fi
grep "Failed to open file"${logFile} if [ $? -eq 0 ]; then Log "存在文件[${localPath}/${fileName}]获取失败, 地址错误或网络不通, 请检查..." Log "日志信息:\n`cat ${logFile}`" exit 1 fi }
lftp -du${ftpUser},${ftpPwd} ftp://${ftpIp} >${logFile} 2>&1 <<FTPFILE set net:timeout 5 set net:max-retries 1 set net:reconnect-interval-multiplier 1 set net:reconnect-interval-base 5 set xfer:clobber on cd ${ftpPath} lcd ${localPath} get ${fileName} bye FTPFILE }
lftp -du${ftpUser},${ftpPwd} ftp://${ftpIp} >${logFile} 2>&1 <<FTPFILE set net:timeout 5 set net:max-retries 1 set net:reconnect-interval-multiplier 1 set net:reconnect-interval-base 5 set xfer:clobber on cd ${ftpPath} lcd ${localPath} mget *.txt bye FTPFILE } # 检查FTP获取文件是否成功 FtpCheck() { logFile=$1 fileName=$2 # 是否有获取数据文件 fileFlag=$3
grep "Fatal error: max-retries exceeded"${logFile} if [ $? -eq 0 ]; then Log "登录FTP服务器[${ftpIp}]失败, 地址错误或网络不通, 请检查..." Log "日志信息:\n`cat ${logFile}`" exit 1 fi
grep "Login failed"${logFile} if [ $? -eq 0 ]; then Log "登录FTP服务器[${ftpIp}]失败, 用户名或密码错误, 请检查..." Log "日志信息:\n`cat ${logFile}`" exit 1 fi
grep "Failed to change directory"${logFile} if [ $? -eq 0 ]; then Log "切换FTP目录[${ftpPath}]失败, 请检查..." Log "日志信息:\n`cat ${logFile}`" exit 1 fi
grep "Failed to open file"${logFile} if [ $? -eq 0 ]; then Log "存在文件[${localPath}/${fileName}]获取失败, 地址错误或网络不通, 请检查..." Log "日志信息:\n`cat ${logFile}`" exit 1 fi
if [ "X${fileFlag}" == "XY" ]; then # no files found 暂不检查 getFlag=`grep "Transfer complete"${logFile}` if [ $? -ne 0 ]; then Log "未获取任何文件, 请检查:\n`cat ${logFile}`" exit 1 else Log "获取文件信息如下:\n`grep -B4 "Transfer complete" ${ftpLog}|awk '/Transfer complete/ {num++} {if ($0 ~ "Transfer complete") {print "第"num"个文件:"$0;} else {print $0;}}'`" fi fi }