Shell实现的 FTP 上传文件的脚本
时间:2014-09-30 21:58 来源:linux.it.net.cn 作者:it
实现ftp上传文件的shell脚本,可以上传一个文件或多个文件。
1,上传单个文件的脚本:
复制代码代码示例:
#!/bin/bash
FTP_SERVER=192.168.8.10
USER="loglogic"
PASSWORD="log1234"
FTP_PATH="/zhu"
LOCAL_PATH="/home/test"
if test -f /$LOCAL_PATH/login.sh
then
# file exits, so upload and print a message.
ftp -i -n $FTP_SERVER < user $USER $PASSWORD
passive
binary
cd /$FTP_PATH
lcd /$LOCAL_PATH
put login.sh # file name
AUTO_PATH
echo "Done!"
else
# file doesn't exit, so we print a message and exit.
echo "This file doesn't exit."
exit
fi
2,上传多个文件的shell脚本:
复制代码代码示例:
#!/bin/bash
# This script is for upload all files as same directory to FTP Server.
FTP_SERVER=192.168.8.10
USER="loglogic"
PWD="log1234"
FTP_PATH="/zhu"
LOCAL_PATH="/home/test"
ftp -i -n $FTP_SERVER < user $USER $PWD
passive
binary
cd /$FTP_PATH
lcd /$LOCAL_PATH
mput *
AUTO_PATH
知识点:
以上脚本中用到了mput命令,这个值得关注下。
另外,在linux下上传文件,可以考虑lftp命令,更快更好用。
(责任编辑:IT)
实现ftp上传文件的shell脚本,可以上传一个文件或多个文件。
1,上传单个文件的脚本:
复制代码代码示例:
#!/bin/bash
if test -f /$LOCAL_PATH/login.sh
put login.sh # file name
2,上传多个文件的shell脚本:
复制代码代码示例:
#!/bin/bash
USER="loglogic"
ftp -i -n $FTP_SERVER < user $USER $PWD
lcd /$LOCAL_PATH
知识点: |