File size: 1,134 Bytes
ed4e767 3916779 d0abea8 3916779 ed4e767 d0abea8 ed4e767 3916779 d0abea8 3916779 ed4e767 d0abea8 e0d681d ed4e767 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
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 的结果
|