ftp retrlines with re...

Peter Otten __peter__ at web.de
Mon Dec 8 05:40:15 EST 2008


isabellknauer at googlemail.com wrote:

> filelist=server.retrlines('LIST')

This does not do what you think it does.

>>> help("ftplib.FTP.retrlines")

gives

"""
Help on method retrlines in module ftplib:

retrlines(self, cmd, callback=None) unbound ftplib.FTP method
    Retrieve data in line mode.
    The argument is a RETR or LIST command.
    The callback function (2nd argument) is called for each line,
    with trailing CRLF stripped.  This creates a new port for you.
    print_line() is the default callback.
"""

I. e. you would need something like

lines = []
server.retrlines("LIST", lines.append)

to store the method's output in a variable instead of printing it to stdout.
But try

files = server.nlist()

instead which gives you a list of filenames. 

Peter

PS: Remember to take Gabriel's advice to heart for your next question.



More information about the Python-list mailing list