Py学习  »  Python

python ioerror:[errno 21]是一个目录

Ratha • 5 年前 • 2275 次点击  

这是我的示例python脚本,我想在其中从sftp服务器下载一个文件到本地。

srv = pysftp.Connection(host=host, username=username, password=password, port=port, cnopts=connOption)
    with srv.cd(sftppath):
        data = srv.listdir()
        try:
            for infile in data:
                print infile
                srv.get(infile, destination, preserve_mtime=True)

我可以成功连接,它列出文件夹中的所有文件。但当我使用srv.get()将AOD下载到桌面时,会出现以下错误:

IOError: [Errno 21] Is a directory: '/Users/ratha/Desktop'

误差叠加;

Traceback (most recent call last):
  File "/Users/ratha/PycharmProjects/SFTPDownloader/handler.py", line 9, in <module>
    main()
  File "/Users/ratha/PycharmProjects/SFTPDownloader/handler.py", line 5, in main
    downloadSFTPFiles()
  File "/Users/ratha/PycharmProjects/SFTPDownloader/Utilities/SFTPConnector.py", line 49, in downloadSFTPFiles
    srv.get(infile, destination, preserve_mtime=True)
  File "/Users/ratha/PycharmProjects/SFTPDownloader/venv/lib/python2.7/site-packages/pysftp/__init__.py", line 249, in get
    self._sftp.get(remotepath, localpath, callback=callback)
  File "/Users/ratha/PycharmProjects/SFTPDownloader/venv/lib/python2.7/site-packages/paramiko/sftp_client.py", line 801, in get
    with open(localpath, "wb") as fl:
IOError: [Errno 21] Is a directory: '/Users/ratha/Desktop'

我在这里做错什么了?

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/37923
 
2275 次点击  
文章 [ 2 ]  |  最新文章 5 年前
blhsing
Reply   •   1 楼
blhsing    6 年前

destination

import os

...

srv.get(infile, os.path.join(destination, os.path.basename(infile)), preserve_mtime=True)
Imperishable Night
Reply   •   2 楼
Imperishable Night    6 年前

    with open(localpath, "wb") as fl:
IOError: [Errno 21] Is a directory: '/Users/ratha/Desktop'

pysftp /Users/ratha/Desktop documentation

os.path.join('/Users/ratha/Desktop', filename)