在 SSH session 中执行的 Python 脚本中保存到另一个驱动器时出现“[Errno 2] 没有这样的文件或目录”
"[Errno 2] No such file or directory" when saving to another drive in Python script executed in SSH session
在服务器机器上:
print("Python Script")
filename = 'C:\..\store.txt'
file = open(filename, 'w')
file.write('text')
file.close()
在服务器机器上 运行 时生成一个名为 store.txt 的文件;它按预期工作。当使用以下脚本通过 SSH 执行时,它的行为也正确:
host = '...'
user = '...'
passwd = '...'
ssh = paramiko.SSHClient()
ssh.load_system_host_keys()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(host, port=22, username=user, password=passwd, look_for_keys=False, allow_agent=False)
command = "C:\path_to_script\script.py"
(stdin, stdout, stderr) = ssh.exec_command(command)
for line in stdout:
print(line)
for line in stderr:
print(line)
当从服务器写入不同的驱动器 O:\...
时,这也按预期工作。
最后,当通过SSH(使用paramiko)执行python脚本时,我得到了标题中的错误:
IOError: [Errno 2] No such file or directory: 'O:\...
文件一开始就'Opened',更不用说写入了。我在 Windows 机器上,关于如何解决这个问题有什么建议吗?
我猜这是一个映射的网络驱动器。
驱动器很可能没有在 SSH 会话中映射。
尝试改用 UNC 路径。
在服务器机器上:
print("Python Script")
filename = 'C:\..\store.txt'
file = open(filename, 'w')
file.write('text')
file.close()
在服务器机器上 运行 时生成一个名为 store.txt 的文件;它按预期工作。当使用以下脚本通过 SSH 执行时,它的行为也正确:
host = '...'
user = '...'
passwd = '...'
ssh = paramiko.SSHClient()
ssh.load_system_host_keys()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(host, port=22, username=user, password=passwd, look_for_keys=False, allow_agent=False)
command = "C:\path_to_script\script.py"
(stdin, stdout, stderr) = ssh.exec_command(command)
for line in stdout:
print(line)
for line in stderr:
print(line)
当从服务器写入不同的驱动器 O:\...
时,这也按预期工作。
最后,当通过SSH(使用paramiko)执行python脚本时,我得到了标题中的错误:
IOError: [Errno 2] No such file or directory: 'O:\...
文件一开始就'Opened',更不用说写入了。我在 Windows 机器上,关于如何解决这个问题有什么建议吗?
我猜这是一个映射的网络驱动器。
驱动器很可能没有在 SSH 会话中映射。
尝试改用 UNC 路径。