背景:
今天同事需要下载一个大数据文件,文件在美国sftp服务器,所以用自己电脑下载太慢,没办法,只能写一个脚本,让它后台下载,要不然下班就下不了了!!
需要工具有:
lftp,sftp
在centos7中安装lftp
yum -y install lftp
一般来说sftp大多数linux发行版本都自带执行sftp会出现以下
[root@instance-7 ~]# sftp usage: sftp [-1246aCfpqrv] [-B buffer_size] [-b batchfile] [-c cipher] [-D sftp_server_path] [-F ssh_config] [-i identity_file] [-l limit] [-o ssh_option] [-P port] [-R num_requests] [-S program] [-s subsystem | sftp_server] host sftp [user@]host[:file ...] sftp [user@]host[:dir[/]] sftp -b batchfile [user@]host
然后新建一个脚本文件
vi downfile.sh
脚本内容:
#!/bin/sh #===================================================== #下载文件到本地服务器 #===================================================== echo " 开始下载文件" #########初始配置数据################################# #链接到cdr sftp服务器上 cd /home lftp sftp://用户名:密码@IP地址:22 <<EOF cd XML get PFA2_201908312200_F.zip bye EOF
授权
chmod 755 downfile.sh
执行下载,我这里就后台运行了
sh downfile.sh &