Python 使用 pysftp 模块上传文件错误提示:OSError: Failure
1.原代码示例如下:
- import pysftp
- def sftp():
- cnopts = pysftp.CnOpts()
- cnopts.hostkeys = None
- sftp = pysftp.Connection('10.0.0.1', port=23653, username='root', password='As6n1c64Tpkt', cnopts=cnopts)
- sftp.put('/www/wwwroot/python/page-weibo-hot.php', '/www/pageTemplates')
- if __name__ == '__main__':
- sftp()
2.执行结果出现错误,无法完成上传动作:
- Traceback (most recent call last):
- File "weibo.py", line 95, in <module>
- sftp()
- File "weibo.py", line 92, in sftp
- sftp.put('C:/Users/Administrator/Desktop/page-weibo-hot.php', '/www/pageTemplates')
- File "D:\Python\Python38-32\lib\site-packages\pysftp\__init__.py", line 363, in put
- sftpattrs = self._sftp.put(localpath, remotepath, callback=callback,
- File "D:\Python\Python38-32\lib\site-packages\paramiko\sftp_client.py", line 759, in put
- return self.putfo(fl, remotepath, file_size, callback, confirm)
- File "D:\Python\Python38-32\lib\site-packages\paramiko\sftp_client.py", line 714, in putfo
- with self.file(remotepath, "wb") as fr:
- File "D:\Python\Python38-32\lib\site-packages\paramiko\sftp_client.py", line 372, in open
- t, msg = self._request(CMD_OPEN, filename, imode, attrblock)
- File "D:\Python\Python38-32\lib\site-packages\paramiko\sftp_client.py", line 857, in _request
- return self._read_response(num)
- File "D:\Python\Python38-32\lib\site-packages\paramiko\sftp_client.py", line 909, in _read_response
- self._convert_status(msg)
- File "D:\Python\Python38-32\lib\site-packages\paramiko\sftp_client.py", line 942, in _convert_status
- raise IOError(text)
- OSError: Failure
3.后经排查发现上传目标目录非文件绝对路径而是文件存放目录,把'/www/pageTemplates改成/www/pageTemplates/page-weibo-hot.php,随后执行成功。
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。