# -*- coding: utf-8 -*- import paramiko from pathlib import Path c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect("107.173.30.245", 4014, "eric", "4669805", timeout=40, allow_agent=False, look_for_keys=False) pw = "4669805" data = Path(r"c:\Users\admin\Desktop\douyinWEB\backend\app\main.py").read_bytes().replace(b"\r\n", b"\n") sftp = c.open_sftp() with sftp.file("/tmp/_main_new.py", "wb") as f: f.write(data) sftp.close() _, o, e = c.exec_command( f"echo '{pw}' | sudo -S -p '' bash -lc " "'install -m 644 /tmp/_main_new.py /opt/douyinWEB/backend/app/main.py; " "grep -n \"Let uvicorn bind\" /opt/douyinWEB/backend/app/main.py | head'", timeout=30, ) print((o.read() + e.read()).decode()) c.close()