import pexpect import argparse # 设置命令行参数解析 parser = argparse.ArgumentParser(description='Rsync files from a remote server to local.') parser.add_argument('--host', required=True, help='Remote host IP address') parser.add_argument('--port', required=True, help='Remote SSH port') args = parser.parse_args() # 定义变量 local_path = "/sillytavern/" # 本地路径 remote_user = "root" remote_host = args.host # 从命令行参数获取远程主机 remote_port = args.port # 从命令行参数获取远程端口 remote_path = "/sillytavern/" # 远程路径 password = "qilan" # 将你的密码放在这里 # 构建 rsync 命令,添加 StrictHostKeyChecking=no,注意源和目标位置的调整 command = f"rsync -avzP -e 'ssh -o StrictHostKeyChecking=no -p {remote_port}' {remote_user}@{remote_host}:{remote_path} {local_path}" # 启动子进程并运行命令 child = pexpect.spawn(command) # 期待 SSH 密码提示并发送密码 child.expect("password:") child.sendline(password) # 等待命令完成并输出结果 child.expect(pexpect.EOF) print(child.before.decode()) # 输出 rsync 的结果