#----------------------------------------------------------- #create file list if [ ${METHOD} = "upload" ]; then if [ ${FILE_LIST} = "undefined" ]; then BATCH_OPT="mput ${FILE_TYPE}" else BATCH_OPT=`sed 's/^/put /g' ${FILE_LIST}` rm -f ${FILE_LIST} fi elif [ ${METHOD} = "download" ]; then if [ ${FILE_LIST} = "undefined" ]; then BATCH_OPT="mget ${FILE_TYPE}" else BATCH_OPT=`sed 's/^/get /g' ${FILE_LIST}` rm -f ${FILE_LIST} fi else error "Tansfer mode(-[U(pload) D(ownload)]) must be set.(2)" fi
#transfer files cd ${WORK_DIR} #excute ftp batch echo " open ${REMOTE_IP} prompt off user ${USER} ${PSWD} lcd ${LOCAL_DIR} cd ${REMOTE_DIR} ${CONN_MODE} ${TRAN_MODE} ${BATCH_OPT} close bye " |ftp -v -n |tee ${TRANSFER_LOG} |sed 's/^/>/g' >> ${RUN_LOG} #执行批量传送, 并记录日志 TOTAL_TRANSFERED=`grep "226 Transfer complete" ${TRANSFER_LOG} |wc -l` #统计传送数量 log "TOTAL TRANSFERED: ${TOTAL_TRANSFERED}" log ""
#clear or backup files if [ ${METHOD} = "upload" ]; then if [ ${BACKUP_DIR} != "undefined" ]; then #备份已上传的文件 log "Backup up files ... " COUNT=0 BATCH_BKUP=`grep -B 3 "226 Transfer complete." ${TRANSFER_LOG} |grep "local:" |awk -F""'{printf("%s\n",$2);}'` cd ${LOCAL_DIR} for I in ${BATCH_BKUP} do mv -v ${I} ${BACKUP_DIR}/ |sed 's/^/>/g' >> ${RUN_LOG} 2>&1 COUNT=`expr ${COUNT} + 1` done log "TOTAL BACKUPED: ${COUNT}" log "" else if [ ${CLEAN} = "true" ]; then #清除已上传的文件 log "Remove transfered files ... " COUNT=0 BATCH_CLEAN=`grep -B 3 "226 Transfer complete." ${TRANSFER_LOG} |grep "local:" |awk -F""'{printf("%s\n",$2);}'` log "Execute local clear(${LOCAL_DIR}) ... " cd ${LOCAL_DIR} for I in ${BATCH_CLEAN} do rm -fv ${I} |sed 's/$/ deleted./g' >> ${RUN_LOG} 2>&1 COUNT=`expr ${COUNT} + 1` done log "TOTAL DELETED: ${COUNT}" log "" fi fi elif [ ${METHOD} = "download" ]; then if [ ${CLEAN} = "true" ]; then #清除已下载的文件 log "Execute remote clear ... " BATCH_CLEAN=`grep -B 3 "226 Transfer complete." ${TRANSFER_LOG} |grep "local:" |awk -F""'{printf("delete %s\n",$2);}'` echo " open ${REMOTE_IP} prompt off user ${USER} ${PSWD} lcd ${LOCAL_DIR} cd ${REMOTE_DIR} ${BATCH_CLEAN} close bye " |ftp -v -n |tee ${TRANSFER_LOG} |sed 's/^/>/g' >> ${RUN_LOG} 2>&1 COUNT=`grep "250 DELE command successful." ${TRANSFER_LOG} |wc -l` log "TOTAL DELETED: ${COUNT}" log "" fi else error "Tansfer mode(-[U(pload) D(ownload)]) must be set.(3)" fi