#!/usr/bin/env python # -*- coding: utf-8 -*- """ @name 上传Feed控制器到服务器 @desc SFTP上传修复后的Feed.php到服务器 @created 2026-06-09 @updated 2026-06-09 """ import paramiko import os # 服务器配置 HOST = '123.207.67.197' PORT = 22 USER = 'root' PASS = '520Kiss123' # 本地文件 -> 远程路径映射 UPLOAD_MAP = { r'docs\toolsapi\application\api\controller\Feed.php': '/www/wwwroot/tools.wktyl.com/application/api/controller/Feed.php', r'docs\toolsapi\application\admin\controller\FeedWeight.php': '/www/wwwroot/tools.wktyl.com/application/admin/controller/FeedWeight.php', r'docs\toolsapi\application\admin\view\feed_weight\index.html': '/www/wwwroot/tools.wktyl.com/application/admin/view/feed_weight/index.html', r'docs\toolsapi\public\assets\js\backend\feed_weight.js': '/www/wwwroot/tools.wktyl.com/public/assets/js/backend/feed_weight.js', } def upload(): local_base = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) print(f"本地项目根目录: {local_base}") ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) print(f"连接服务器 {HOST}:{PORT}...") ssh.connect(HOST, port=PORT, username=USER, password=PASS, timeout=15) sftp = ssh.open_sftp() print("连接成功!") for local_rel, remote_path in UPLOAD_MAP.items(): local_path = os.path.join(local_base, local_rel) if not os.path.exists(local_path): print(f"[跳过] 本地文件不存在: {local_path}") continue # 确保远程目录存在 remote_dir = os.path.dirname(remote_path) try: sftp.stat(remote_dir) except FileNotFoundError: print(f" 创建远程目录: {remote_dir}") print(f"上传: {local_rel} -> {remote_path}") sftp.put(local_path, remote_path) print(f" ✓ 上传成功") sftp.close() # 清除服务器缓存 print("\n清除服务器运行时缓存...") stdin, stdout, stderr = ssh.exec_command('rm -rf /www/wwwroot/tools.wktyl.com/runtime/cache/*') print(f" 缓存清除: {stdout.read().decode()}") ssh.close() print("\n✓ 全部上传完成!") if __name__ == '__main__': upload()