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()