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

snowf snowf200807 at gmail.com
Wed Sep 6 02:29:55 EDT 2006


John Machin wrote:
> 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
Thanks for you reply!
I will have a  try with  your suggest and show the result later.




More information about the Python-list mailing list