自由Man

SFTP批量搜索下载Shell脚本

最近有个需求是:需要在服务器上下载一批文件,但这些文件又分布在不同服务器上,不知道哪些文件位于什么服务器上。使用SFTP客户端只能一个一个下载,太慢了!!!

网上搜索,未找到相关脚本,只有很多批量上传、单个下载的。将最终的shell脚本分享出来,一方面,mark一下;另一方面供有需要的朋友使用。

脚本batdown.sh

#!/usr/bin/expect
set timeout -1
set userna tmpsftp
set passwd 1qaz@WSX
set ip 100.168.103.108
set dir /output
spawn sftp $userna@$ip
expect "password:"
send $passwd\r
expect "sftp> "
send -- "cd $dir\r"
set filename "./caselist.txt"
set content [open $filename r+]
while {[gets $content line] >= 0} {
expect "sftp> "
send -- "get ${line}*\r"
}
close $content
expect "sftp>"
send -- "bye\r"
expect eof

将所有待下载文件存储到列表文件caselist.txt。

执行batdown.sh即可!

  • 评论列表:

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

Powered By Z-BlogPHP 1.5.2 Zero Theme By 爱墙纸

Copyright ZiYouMan.cn. All Rights Reserved. 蜀ICP备15004526号