码迷,mamicode.com
首页 > Web开发 > 详细

FTP客户端Shell脚本,实现指定目录下逐个上传文件

时间:2021-06-15 17:53:21      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:led   bash   上传   pre   use   name   style   nbsp   loaded   

 

脚本内容:

#!/bin/bash


function findProc() {
        PROC_NAME=ftp
        ProcNumber=`ps -ef |grep -w $PROC_NAME|grep -v grep|wc -l`
        if [ $ProcNumber -le 0 ];then
                fileftp
                exit
        else
                sleep 120
                findProc
        fi
}


function fileftp() {
        USER=uploadfile
        PASS=uploadfile
        HOST=192.168.10.69
        PORT=21
        uploadDir=/home/uploadfile/

        for upfile in `ls $uploadDir`
        do
        exec 6>&1 1>/tmp/ftptmp.txt
        ftp -nv<<!
        open $HOST $PORT
        user $USER $PASS
        binary
        lcd $uploadDir
        put $upfile
        close
        bye
!

        exec 1>&6
        exec 6>&-
        if grep -q "Transfer complete" /tmp/ftptmp.txt;then
                echo -n "`date ‘+%Y-%m-%d %H:%M‘` ---> " >> /home/uploadfile/upload_ftp.log
                echo    "$upfile has been successfully uploaded." >> /home/uploadfile/upload_ftp.log
                if [ $upfile != "upload_ftp.log" ];then
                rm -f $uploadDir/$upfile
                fi
        else
                echo -n "`date ‘+%Y-%m-%d %H:%M‘` ---> " >> /home/uploadfile/upload_ftp.log
                echo    "$upfile uploaded failed." >> /home/uploadfile/upload_ftp.log
        fi
        done
}

findProc

 

FTP客户端Shell脚本,实现指定目录下逐个上传文件

标签:led   bash   上传   pre   use   name   style   nbsp   loaded   

原文地址:https://www.cnblogs.com/caoyibin/p/14883265.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!