from:https://www.cnblogs.com/my-first-blog-lgz/p/13590313.html
一、批量上传:
#!/bin/bash
#SFTP配置信息
#用户名
USER=root
#密码
PASSWORD=5EYS40T04BMF
#待上传文件根目录
SRCDIR=/u02/dab/sftpFiles
#FTP目录
DESDIR=/u01/sftpFiles
#IP
IP=192.168.10.11
#端口
PORT=22022
#获取文件
cd ${SRCDIR} ;
#目录下的所有文件
#FILES=`ls`
#修改时间在执行时间五分钟之前的xml文件
FILES=`find ${SRCDIR} -mmin -50 -name '*.xml'`
for FILE in ${FILES}
do
echo ${FILE}
#发送文件 (关键部分)
lftp -u ${USER},${PASSWORD} sftp://${IP}:${PORT} <<EOF
cd ${DESDIR}/
lcd ${SRCDIR}
put ${FILE}
by
EOF
in shell command mode (single input) do not add "<<EOF" ==> it will prompt secondary shell waiting for response, which is actually the interactive shell of the current command line
i.e. lftp
二、单个文件下载:
#!/bin/bash
USER=root
#密码
PASSWORD=5EYS40T04BMF
#下载文件目录
SRCDIR=/u02/dab
#FTP目录(待下载文件目录)
DESDIR=/u01/sftpFiles
#银联IP
IP=192.168.1.10
#端口
PORT=22022
#需要下载的文件为fileName
fileName="booking_`date +%Y%m%d%H`.sql"
lftp -u ${USER},${PASSWORD} sftp://${IP}:${PORT}<<EOF
cd ${DESDIR}
lcd ${SRCDIR}
get $fileName
by
EOF