pip install paramiko
import paramiko
class SSHClient:
def __init__(self, host, port, username, password):
self.host = host
self.port = port
self.username = username
self.password = password
self.ssh = None
self.sftp = None
def connect(self):
"""连接到远程服务器"""
try:
print(f"Connecting to {self.host}...")
self.ssh = paramiko.SSHClient()
self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
self.ssh.connect(
hostname=self.host, port=self.port,
username=self.username, password=self.password