# -*- coding: utf-8 -*- import paramiko c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect("107.173.30.245", 22, "root", "Xiao4669805", timeout=30, allow_agent=False, look_for_keys=False) sftp = c.open_sftp() sftp.put( r"C:/Users/admin/Desktop/douyinWEB/backend/app/ops_panel.py", "/opt/douyinWEB/backend/app/ops_panel.py", ) sftp.close() def run(cmd, timeout=120): _, o, e = c.exec_command(cmd, timeout=timeout) return (o.read() + e.read()).decode("utf-8", "replace").strip() print(run("systemctl restart douyinweb-api; sleep 4; systemctl is-active douyinweb-api")) print( run( "cd /opt/douyinWEB/backend && .venv/bin/python -c \"" "from app.ops_panel import send_ntfy; " "print(send_ntfy('DouyinWEB 测试', '来自 /ops 控制台的 ntfy 测试消息', 'default', 'bell', 'dylive'))\"" ) ) c.close()