使用put时Paramiko错误
你好,我在使用 paramiko 1.7.6 "fanny" 这个库,运行在 Windows XP v2002 服务包3 上,使用的是 Python 2.4.2。
我有以下这个脚本:
import paramiko
hostname='blah'
port=22
username='blah'
password='blah'
fullpath='\\\\root\\path\\file.xls'
remotepath='/inbox/file.xls'
self.client= paramiko.SSHClient()
self.client.load_system_host_keys()
self.client.connect(hostname,port,username,password)
sftp = self.client.open_sftp()
sftp.put(fullpath,remotepath)
我遇到的错误是:
sftp.put(fullpath,remotepath))
File "build\bdist.win32\egg\paramiko\sftp_client.py", line 577, in put
File "build\bdist.win32\egg\paramiko\sftp_client.py", line 337, in stat
File "build\bdist.win32\egg\paramiko\sftp_client.py", line 628, in _request
File "build\bdist.win32\egg\paramiko\sftp_client.py", line 675, in _read_response
File "build\bdist.win32\egg\paramiko\sftp_client.py", line 701, in _convert_status
IOError: [Errno 2] /inbox/file.xls is not a valid file path
但是这个路径确实是存在的(我可以通过 sftp.chdir('inbox') 进入这个路径)。我也试过直接进入文件夹后使用 put 命令,但还是遇到同样的错误(确实去掉了 inbox 前缀)。
有没有人遇到过这个问题?
谢谢,
matt
2 个回答
1
我也遇到过同样的问题。
这个函数的定义是 sftp_client.py 里的:
def put(self, localpath, remotepath, callback=None, confirm=True):
很多论坛的回答都把第一个参数称作远程路径。
但如果我们把第一个参数改成本地路径,第二个参数改成远程路径,
这样就可以正常工作了。
没有任何问题。
1
你遇到的错误是 IOError: [Errno 2] /inbox/file.xls is not a valid file path
。
这个错误的意思是说,/inbox 这个路径不对。你可能是想用
remotepath='inbox/file.xls'
。