How to get all the file of a oppoint directory from a FTP

John Machin sjmachin at
Wed Sep 6 08:10:35 CEST 2006

snowf wrote:
> There are no such a method using to download a whole directory  in  the
> lib of  ' ftplib '.
> thanks for anybody's help!

So you'll have to lash one up:


    alist = []
    ftpobj.retrlines('list', alist.append)
should get you a list of filenames.


for fname in alist:
    f = open(fname, "wb")
    ftpobj.retrbinary('RETR ' + fname, f.write)

should do the business. Instead of using f.write as the callback, you
might like to wrap that in a function that counts the bytes received,
displays progress, etc.


More information about the Python-list mailing list