ftplib limitations?

durumdara durumdara at gmail.com
Tue Aug 24 11:21:00 CEST 2010


See this code:


import os, sys, ftplib

from ftplib import FTP
ftp = FTP()
ftp.connect('ftp.anything.hu', 2121)
ftp.login('?', '?')
print ftp.getwelcome()
ls = ftp.nlst()

for s in ls:

    print "\nFilename:", '"%s"' % s,
    fsize = ftp.size(s)
    print "Size:", fsize
    print "..download:",

    d = {}
    d['buffer'] = []
    d['size'] = 0
    d['lastpercentp10'] = 0
    def CallBack(Data):
        d['size'] = d['size'] + len(Data)
        percent = (d['size'] / float(fsize)) * 100
        percentp10 = int(percent/10)
        if percentp10 > d['lastpercentp10']:
            d['lastpercentp10'] = percentp10
            print str(percentp10 * 10) + "%",

    ftp.retrbinary("retr " + s, CallBack)
    print ""
    print "..downloaded, joining"
    dbuffer = "".join(d['buffer'])
    adir = os.path.abspath("b:\\_BACKUP_")
    newfilename = os.path.join(adir, s)
    print "..saving into", newfilename
    f = open(newfilename, "wb")
    print "..saved"
    print "..delete from the server"
    print "..deleted"

print "\nFinished"


This code is login into a site, download and delete all files.

I experienced some problem.
The server is Windows and FileZilla, the client is Win7 and Python2.6.
When I got a file with size 1 303 318 662 byte, python is halt on
"retrbinary" line everytime.
It down all of the file (100%) but the next line never reached.
Some error I got, but this was in yesterday, I don't remember the text
of the error.

I want to ask that have Py2.6 some ftp limitations?

I remembered that Zip have 2 GB limitation, the bigger size of the
archive making infinite loop.

May ftplib also have this, and this cause the problem... Or I need to
add a "NOOP" command in Callback?

Thanks for your help:

More information about the Python-list mailing list