python-scp-上传文件到服务器

python中使用scp,将文件上传到服务器

 1 def ssh_scp_put(ip, username, password, local_file, remote_path):
 2     """
 3     scp上传文件
 4     :param ip:
 5     :param username:
 6     :param password:
 7     :param local_file:
 8     :param remote_path:
 9     :return:
10     """
11     ssh = paramiko.SSHClient()
12     ssh.load_system_host_keys()
13     ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
14 
15     ssh.connect(hostname=str(ip), port=22, username=username, password=password)
16 
17     scp = SCPClient(ssh.get_transport())
18     scp.put(local_file, recursive=True, remote_path=remote_path)
19     scp.close()

 

posted @ 2019-11-29 17:37  小嘉欣  阅读(1938)  评论(0编辑  收藏  举报