Python远程拷贝文件夹/文件

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()
发布了19 篇原创文章 · 获赞 3 · 访问量 4953

猜你喜欢

转载自blog.csdn.net/xiaojian0907/article/details/103176671