Paramiko从一台服务器拷贝文件到另外一台服务器
import paramiko
# 连接主机1
ssh1 = paramiko.SSHClient()
ssh1.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh1.connect('192.168.1.1', 22, 'root', '*****', timeout=60)
sftp1 = ssh1.open_sftp()
# 连接主机2
ssh2 = paramiko.SSHClient()
ssh2.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh2.connect('192.168.1.2', 22, 'root', '******', timeout=60)
sftp2 = ssh2.open_sftp()
# 从主机1拷贝文件到主机2
with sftp2.open('/home/hzc/ec.key', 'wb') as fl:
sftp1.getfo('/home/hzc/ec.key', fl)