Entry
Parsing FTP directory
Jul 5th, 2000 09:59
Nathan Wallace, unknown unknown, Hans Nowak, Snippet 99, Michael P. Reilly
"""
Packages: text.parsing;networking.internet
"""
"""
: I'm trying to parse the dir listing recieved from an "ftp.retrlines('LIST')"
: function. The function lists the directory contents in the interpreter
: without any problem. The documentation for the ftplib indicates you can
: include a callback function as second argument to the above function. I
: don't understand how to use this to make a function that can grab these
: lines. My ultimate goal is to grab the actual filenames in the directory so
: the ftp client can then download them. I know how I could parse out a
: directory listing but I don't know how to get the directory listing into a
: usable variable.
: Thank you,
: Ben
You might want to use the nlst method instead.
"""
from ftplib import FTP
conn = FTP('localhost')
conn.login()
print conn.nlst()
# ['bin', 'dev', 'etc', 'in-coming', 'index.html', 'pub', 'tmp', 'usr']
conn.quit()