脚本参考实例
#!/bin/bash
source /etc/profile
source ~/.bash_profile
cd /home/ftp/
yesterday=`date -d "-1 days" +%Y-%m-%d`
FTP_SERVER="xxx.xx.xx.xxx"
FTP_USER=user
FTP_PASS=password
FILE_DATA=="${yesterday}.zip"
if [ ! -f "${FILE_DATA}" ]; then
echo "文件 ${FILE_DATA} 不存在,退出脚本。"
exit 1
fi
ftp -v -n "${FTP_SERVER}" << EOF
user ${FTP_USER} ${FTP_PASS}
binary
prompt
mput ${file_data}
bye
EOF
if [ "${?}" -ne 0 ]; then
echo "FTP命令执行失败,退出脚本。"
exit 1
fi
echo "文件上传成功。"
FTP传输日志注释
Connected to xxx.xx.xx.xxx (xxx.xx.xx.xxx).
220 (vsFTPd 3.0.2)
331 Please specify the password.
230 Login successful.
200 Switching to Binary mode.
Interactive mode off.
local: file_data.zip remote: file_data.zip
227 Entering Passive Mode (xxx,xx,xx,xxx,178,41).
150 Ok to send data.
226 Transfer complete.
400621999 bytes sent in 157 secs (2556.53 Kbytes/sec)