Python ftplib:低下载&使用python ftplib时上传速度 [英] Python ftplib: low download & upload speeds when using python ftplib

查看:334
本文介绍了Python ftplib:低下载&使用python ftplib时上传速度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有人观察到,使用Python的 ftplib 通过ftp下载或上传文件的时间与执行FTP get / put over windows命令提示符或使用Perl的 Net :: FTP 模块。

I was wondering if any one observed that the time taken to download or upload a file over ftp using Python's ftplib is very large as compared to performing FTP get/put over windows command prompt or using Perl's Net::FTP module.

我创建了一个类似于 http://code.activestate.com/recipes/521925-python-ftp-client/ 但我无法达到速度我在Windows DOS提示符下运行FTP或使用perl时得到的。是否有我丢失的东西,或者它是Python ftplib模块的问题。

I created a simple FTP client similar to http://code.activestate.com/recipes/521925-python-ftp-client/ but I am unable to attain the speed which I get when running FTP at the Windows DOS prompt or using perl. Is there something I am missing or is it a problem with the Python ftplib module.

如果你能说出为什么我的吞吐量低,我将非常感激使用Python。

I would really appreciate if you could throw some light as to why I am getting low throughput with Python.

推荐答案

问题出在块大小上,我使用的块大小太小了。在将块大小增加到250Kb后,所有不同平台的速度都是相似的。

The problem was with the block size, i was using a block size of 1024 which was too small. After increasing the block size to 250Kb the speeds are similar across all the different platforms.

def putfile(file=file, site=site, dir=dir, user=())
    upFile = open(file, 'rb')
    handle = ftplib.FTP(site)
    apply(handle.login, user)
    print "Upload started"
    handle.storbinary('STOR ' + file, upFile, 262144)
    print "Upload completed"
    handle.quit()
    upFile.close()

这篇关于Python ftplib:低下载&使用python ftplib时上传速度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆