ftp: get list of files

Lawrence Oluyede raims at dot.com
Tue Feb 7 06:35:08 EST 2006


"eels" <eels at nikocity.de> writes:

> With yyy = ftp.retrlines('LIST') I get this listing at stdout, but I
> need this information at variable yyy.
> How can I resolve this problem?

As written in the doc retrlines has an optional parameter (a callback function)
called on each line retrieved, so you can do something like this:

from ftplib import FTP

def writeline(data):
    fd.write(data + "\n")

f = FTP('ftp.kernel.org')
f.login()

f.cwd('/pub/linux/kernel')
fd = open('README', 'wt')
f.retrlines('RETR README', writeline)
fd.close()
f.quit()


-- 
Lawrence - http://www.oluyede.org/blog
"Anyone can freely use whatever he wants but the light at the end
of the tunnel for most of his problems is Python"



More information about the Python-list mailing list