[NEWBIE] ftplib again...

Steve Holden sholden at holdenweb.com
Thu Feb 7 16:55:47 EST 2002


"Bruce Dykes" <bkd at graphnet.com> wrote ...
> Okay...I've got the ftp connections working...thing is, when I did my
> initial prototyping, I used a local file, and readlines() to get the data
> from the file into a list, and to create the function to parse out the
> useful data from noise. Well it worked as far as getting the processing
> logic down, but now that I'm trying from ftp'ed files, well...
>
> All I need to do is get the file contents into a list. That's it. Now it
> looks as if retrlines("RETR filename") will do that, with some additional
> manipulations.
>
> But it doesn't. Every single variation I've tried,
> dataset=[host.retrlines("RETR filename") ],  host.retrlines("RETR
filename",
> dataset.append) , dataset=list(host.retrlines("RETR filename") ), etc.
> always results in the file contents getting dumped to the
> console/stdout/interactive window, and the completion code, '226 Command
> Completed Successfully' getting assigned to the variable.
>
> What am I missing? Do you need to see more of my code?
>
"""
retrlines (command[, callback])
Retrieve a file or directory listing in ASCII transfer mode. command should
be an appropriate "RETR" command (see retrbinary() or a "LIST" command
(usually just the string 'LIST'). The callback function is called for each
line, with the trailing CRLF stripped. The default callback prints the line
to sys.stdout.
"""
This doesn't really make it that obvious, but what you have to do is provide
a callback, which is called, with the line as an argument, each time a line
is retrieved from the server. The code you need is something like this:

linelist = []
host.retrlines("RETR filename", linelist.append)

After which, linelist will be a list of non-terminated lines.

regards
 Steve
--
Consulting, training, speaking: http://www.holdenweb.com/
Author, Python Web Programming: http://pydish.holdenweb.com/pwp/

"This is Python.  We don't care much about theory, except where it
intersects with useful practice."  Aahz Maruch on c.l.py







More information about the Python-list mailing list