Sftp 文件传输样例,区别于expect交互的方式,流程稍微简单了一点,但是也需要sshpass支持,
直接联网安装sshpass最好,离线安装则需要到官网进行下载,建议下载低版本,不然服务器的lib版本不支持,网址如下:
#!/bin/bash
# 设置变量
source_file="xxxx/*.gz"
remote_path="/xxxx/"
target_server="172.xx.xxx.xxx"
username="xxx"
password="xxxx"# 登录远程服务器,并传输文件
sshpass -p "$password" sftp -oBatchMode=no -b - "$username@$target_server" <<EOF
put $source_file $remote_path
bye
EOF

1万+

被折叠的 条评论
为什么被折叠?



