使用shell 连接sftp,避坑指南

第一个 can’t be established 遇到这个问题
SSH出现can’t be established解决方法:
这个原因可能是本地主机的key发生了变化,因此每次SSH链接都会有提示,只需要在交互下输入yes即可。
当然如果长久的想解决问题,可以采用以下方法:
修改/etc/ssh/ssh_config文件的配置,以后则不会再出现此问题
最后面添加:
StrictHostKeyChecking no
UserKnownHostsFile /dev/null

**第二个 known_hosts **
说明的known_hosts文件的权限有问题
Are you sure you want to continue connecting (yes/no)? yes Failed to add the host to the list of known hosts
su - root
chmod 644 ~/./ssh/known_hosts

ip='xxx.xxx.xxx.xxx'
user='ftpuser'
passwd='123456'
port='12121'
targdir=data
localpath='/pardata/EDASCRIPT/publisher0/CLOUDZDP/source/'
function download_data(){
day=`date "+%Y%m%d"`
expect  <<- EOF
set timeout 5
spawn sftp -oPort=$port $user@$ip
expect {
		        "yes/no" { send "yes\n";exp_continue }
		        "password" { send "$passwd\n" }
}
expect "sftp>"
send "cd $targdir\r"
expect "sftp>"
send "lcd $localpath\r"
set timeout -1
expect "sftp>"
send "mget 10000*$day*\r"
expect "sftp>"
send "bye\r"
EOF
}
  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值