Python远程拷贝文件夹/文件
通过paramiko的ssh和scp的方法,从远程服务器拷贝文件/文件夹到本地指定文件
def scp_remote_file(remote_file_list, local_file):
ssh_client = paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy)
ssh_client.connect(hostname="", port=22, username="", password="")
scp_client = SCPClient(ssh_client.get_transport(), socket_timeout=15.0)
for i in remote_file_list:
try:
scp_client.get(i, local_file + i.split("/")[1] + "_" + i.split("/")[2], True)
except Exception as e:
print("scp remote file error: {}".format(e))
continue
scp_client.close()
ssh_client.close()