Python 使用 pysftp 模块上传文件错误提示:OSError: Failure

Python 使用 pysftp 模块上传文件错误提示:OSError: Failure

Python 使用 pysftp 模块上传文件错误提示:OSError: Failure

1.原代码示例如下:

  1. import pysftp  
  2.   
  3. def sftp():  
  4.     cnopts = pysftp.CnOpts()  
  5.     cnopts.hostkeys = None  
  6.     sftp = pysftp.Connection('10.0.0.1', port=23653, username='root', password='As6n1c64Tpkt', cnopts=cnopts)  
  7.     sftp.put('/www/wwwroot/python/page-weibo-hot.php', '/www/pageTemplates')  
  8. if __name__ == '__main__':  
  9.     sftp()  

2.执行结果出现错误,无法完成上传动作:

  1. Traceback (most recent call last):  
  2.   File "weibo.py", line 95, in <module>  
  3.     sftp()  
  4.   File "weibo.py", line 92, in sftp  
  5.     sftp.put('C:/Users/Administrator/Desktop/page-weibo-hot.php', '/www/pageTemplates')  
  6.   File "D:\Python\Python38-32\lib\site-packages\pysftp\__init__.py", line 363, in put  
  7.     sftpattrs = self._sftp.put(localpath, remotepath, callback=callback,  
  8.   File "D:\Python\Python38-32\lib\site-packages\paramiko\sftp_client.py", line 759, in put  
  9.     return self.putfo(fl, remotepath, file_size, callback, confirm)  
  10.   File "D:\Python\Python38-32\lib\site-packages\paramiko\sftp_client.py", line 714, in putfo  
  11.     with self.file(remotepath, "wb") as fr:  
  12.   File "D:\Python\Python38-32\lib\site-packages\paramiko\sftp_client.py", line 372, in open  
  13.     t, msg = self._request(CMD_OPEN, filename, imode, attrblock)  
  14.   File "D:\Python\Python38-32\lib\site-packages\paramiko\sftp_client.py", line 857, in _request  
  15.     return self._read_response(num)  
  16.   File "D:\Python\Python38-32\lib\site-packages\paramiko\sftp_client.py", line 909, in _read_response  
  17.     self._convert_status(msg)  
  18.   File "D:\Python\Python38-32\lib\site-packages\paramiko\sftp_client.py", line 942, in _convert_status  
  19.     raise IOError(text)  
  20. OSError: Failure  

3.后经排查发现上传目标目录非文件绝对路径而是文件存放目录,把'/www/pageTemplates改成/www/pageTemplates/page-weibo-hot.php,随后执行成功。

Python 使用 pysftp 模块上传文件错误提示:OSError: Failure

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
搜索