Files
xianyan/Scripts/upload_agreements.py
2026-06-27 04:57:00 +08:00

42 lines
1.1 KiB
Python

#!/usr/bin/env python3
"""上传协议文件到服务器"""
import paramiko
import os
import glob
HOST = '123.207.67.197'
PORT = 2026
USER = 'root'
PASS = '520Kiss123'
REMOTE_DIR = '/www/wwwroot/tools.wktyl.com/public/agreements/'
LOCAL_DIR = os.path.join(os.path.dirname(__file__), '..', 'docs', 'toolsapi', 'public', 'agreements')
def main():
local_dir = os.path.abspath(LOCAL_DIR)
html_files = glob.glob(os.path.join(local_dir, '*.html'))
print(f"找到 {len(html_files)} 个协议文件待上传")
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(HOST, port=PORT, username=USER, password=PASS, timeout=15)
sftp = ssh.open_sftp()
# 确保远程目录存在
try:
sftp.stat(REMOTE_DIR)
except FileNotFoundError:
sftp.mkdir(REMOTE_DIR)
for f in html_files:
fname = os.path.basename(f)
remote_path = REMOTE_DIR + fname
print(f" 上传: {fname} -> {remote_path}")
sftp.put(f, remote_path)
sftp.close()
ssh.close()
print(f"✅ 全部 {len(html_files)} 个文件上传完成")
if __name__ == '__main__':
main()