【问题标题】:Python ftp big file downloadPython ftp大文件下载
【发布时间】:2015-08-12 08:06:53
【问题描述】:

首先很抱歉,我无法访问gitHubsourceForge.net,所以我无法检索这样的解决方案:possible answer

我有半个千兆 (510199112 bytes) 可以通过 ftp 下载但出现超时错误:

ftplib.error_temp: 450 Socket write to client timed-out.

我想管理我的超时但不知道如何在我当前的代码中继续:

    ftp_host = 'someFTP'
    login_user = 'johnDoe'
    pwd = 'secret'

    print "connection to ftp %s with user %s" %(ftp_host,login_user)
    ftp = ftplib.FTP(ftp_host)
    ftp.set_debuglevel(1)
    ftp.login(login_user,pwd)

    filename = 'bigFile.txt'
    destination = open('C:/mydestination')

    try:
        print "retrieving file %s to %s" % (filename, destination)
        ftp.retrbinary('RETR %s' % filename, destination.write)
    except Exception as e:
       destination.close()
       print "closing connection"
       ftp.quit()
       raise
    print "closing connection"
    ftp.quit()

    destination.close()

【问题讨论】:

  • 您是否尝试过您引用的问题中的套接字选项?这些相同的套接字选项在您当前无法访问的 github 答案中被重用。由于答案中引用的 github 存储库中的代码(MIT 许可)只有几百行长,因此找到一种获取它的方法应该很简单,特别是因为您似乎可以访问 stackoverflow...
  • 套接字选项是什么意思?对不起,我真的不太熟悉背后的概念,请进一步解释!

标签: python python-2.7 ftp ftplib


【解决方案1】:

你可以尝试使用python的wget库。

import wget
link = 'ftp://example-destination.com/foo.txt'
wget.download(link)

【讨论】:

    猜你喜欢
    • 2012-01-09
    • 2021-10-10
    • 1970-01-01
    • 1970-01-01
    • 2012-10-04
    • 2012-07-30
    • 1970-01-01
    • 1970-01-01
    • 2014-08-05
    相关资源
    最近更新 更多