FTP客户端Shell脚本,实现指定目录下逐个上传文件
脚本内容:
#!/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