sftp文件上传(从本地上传到远程)
#!/bin/bash
#远程上传文件测试
if [ $# -ne 2 ]
then
echo "miss arguments"
echo "need 2 arguments:BAT_DATE,SEQ_NO"
exit -1
fi
source $HOME/.bash_profile
#parameters
BAT_DATE=$1
SEQ_NO=$2
#定义变量
ftp_ip=144.131.254.138
ftp_user=oracle
ftp_password=jkl_2016
ftp_dir=/data/lw
GZ_DIR=/home/dbbatch03/lw
send_file_name="impDHJT.sh"
#执行文件上传命令
/usr/bin/expect <<-EOF
set timeout 10
spawn sftp $ftp_user@$ftp_ip
expect {
"*yes/no*" { send "yes
"; exp_continue }
"*assword:" { send "$ftp_password
" }
}
expect "sftp>"
send "lcd ${GZ_DIR}
"
expect "sftp>"
send "cd ${ftp_dir}
"
expect "sftp>"
set timeout -1
send "put $send_file_name $send_file_name
"
expect "sftp>"
send "quit
"
expect eof
EOF
SetCmdRslt $SEQ_NO 2
复制代码
说明:
1.expect的用法
-[链接网址]: blog.csdn.net/catoop/arti… "请点击这里"
2.expect命令详解
[链接网址]:imysql.cn/2008_11_21_…
3.put命令
put:上传文件。 用法:put 要上传的文件名 上传后的文件名
sftp从远程下载文件到本地(最基础的测试)
#!/bin/bash
#远程下载文件测试:需要自己手动输入密码
if [ $# -ne 2 ]
then
echo "miss arguments"
echo "need 2 arguments:BAT_DATE,SEQ_NO"
exit -1
fi
source $HOME/.bash_profile
#parameters
BAT_DATE=$1
SEQ_NO=$2
#定义变量
ftpIp=$144.131.254.138
ftpUser=oracle
ftpPwd=jkl_2016
ftpDir=/opt/oracle/dcfile/idcheck/20180316/t_black_certid_ciis_${BAT_DATE}.txt
localDir=/home/dbbatch03/dcfile/idcheck/${BAT_DATE}
#执行命令
sftp $ftpUser@$ftpIp <<EOF
get $ftpDir $localDir
quit
EOF
SetCmdRslt $SEQ_NO 2
复制代码
说明
1.直接使用sftp命令,手动输入密码
2.命令介绍
[参考网址]:blog.csdn.net/u012204058/…
sftp远程下载文件(推荐使用)
#!/bin/bash
#从138库上下载文件到10库
if [ $# -ne 2 ]
then
echo "miss arguments"
echo "need 2 arguments:BAT_DATE,SEQ_NO"
exit -1
fi
source $HOME/.bash_profile
#parameters
BAT_DATE=$1
SEQ_NO=$2
#定义变量
FTP_IP=144.131.254.138
FTP_USER=oracle
FTP_USER_PWD=jkl_2016
FTP_PWD=/opt/oracle/dcfile/idcheck/$BAT_DATE
TB_FILE_NAME1=t_black_certid_ciis_${BAT_DATE}.txt
TB_FILE_NAME2=t_black_mchnt_ciis_${BAT_DATE}.txt
BASE_DIR=$HOME/dcfile/idcheck
#执行命令
/usr/bin/expect <<-EOF
set timeout 10
spawn sftp $FTP_USER@$FTP_IP
expect {
"*yes/no*" { send "yes
"; exp_continue }
"*assword:" { send "$FTP_USER_PWD
" }
}
expect "sftp>"
send "lcd $BASE_DIR/$BAT_DATE
"
expect "sftp>"
send "cd $FTP_PWD
"
expect "sftp>"
set timeout -1
send "get *.*
"
expect "sftp>"
send "bye
"
expect eof
EOF
SetCmdRslt $SEQ_NO 2
复制代码
提醒:不要忘记expect "sftp>"
[参考网址:]blog.csdn.net/zhangjingsh…
ftp上传文件
#!/usr/bin/ksh
#修改成ftp形式上传文件
#created by zhaojj on 14/12/2017
if [ $# -ne 6 ]
then
echo "使用ftp发送文件"
echo "ftp_user:用户名"
echo "ftp_ip:ip"
echo "ftp_password:密码"
echo "ldirName:本地目录"
echo "ftpdirName:远程目录"
echo "send_file_name:要发送的文件名"
exit
fi
ftp_user=$1
ftp_ip=$2
ftp_password=$3
ldirName=$4
ftpdirName=$5
send_file_name=$6
#!/bin/bash
set timeout 10
ftp -n <<- EOF
open $ftp_ip
user $ftp_user $ftp_password
binary
cd $ftpdirName
lcd $ldirName
set timeout -1
bin
put $send_file_name 20171219_$send_file_name
close
bye
EOF
if [ $? -ne 0 ]
then
SetCmdRslt $SEQ_NO 3
exit -1
fi
SetCmdRslt $SEQ_NO 2
复制代码
转载于:https://juejin.im/post/5abb3b9d6fb9a028da7c9383