python调用scp通信模块发送文件
import paramiko
from scp import SCPClient
def scp_send_files(host, port, username, password, local_path, remote_path):
"""
使用SCP发送文件到远程服务器
:param host: 远程服务器主机名或IP地址
:param port: 远程服务器端口号,默认为22
:param username: 登录远程服务器的用户名
:param password: 登录远程服务器的密码
:param local_path: 本地文件或文件夹路径
:param remote_path: 远程服务器的目标路径
"""
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(host, port, username, password)
with SCPClient(ssh.get_transport()) as scp:
scp.put(local_path, remote_path, recursive=True)
ssh.close()