python 刺激 ssh - 使用 set 命令

python spur ssh - use set command

我正在使用以下命令通过 ssh 连接到 windows 服务器,我正在尝试使用 set 命令。这是我在本地使用的有效方法:

set ASPERA_SCP_PASS=myPassword
ascp /directory/Test4.mov myAccount@10.1.1.1:/TEST

这是我的 python 命令:

shell = spur.SshShell(hostname=10.0.0.1, username=Wusername, password=Wpassword, missing_host_key=spur.ssh.MissingHostKey.accept)
result = shell.run(["set", "ASPERA_SCP_PASS=myPassword])
result = shell.run(["ascp.exe", "/directory/Test4.mov", "myAccount@10.1.1.1:/TEST"])

当 运行 以上时,我通过 ssh 成功连接,但我在 set 命令上收到此错误:

spur.results.RunProcessError: return code: 127
output: b''
stderr output: b'sh: line 0: exec: set: not found\n'

我发现这很好用:

environment = {}
environment["ASPERA_SCP_PASS"] = "password"
shell = spur.SshShell(hostname="10.1.1.1", username="username", password="passowrd", missing_host_key=spur.ssh.MissingHostKey.accept)
result = shell.run(["ascp.exe", directory, "Ausername@10.0.0.1:/"], stdout=sys.stdout, update_env=environment)