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

John Machin sjmachin at lexicon.net
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:

(untested)

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

Secondly,

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

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.

HTH,
John




More information about the Python-list mailing list