[NEWBIE] ftplib again...

Bruce Dykes bkd at graphnet.com
Fri Feb 8 10:05:03 EST 2002


----- Original Message -----
From: "Steve Holden" <sholden at holdenweb.com>
Newsgroups: comp.lang.python
To: <python-list at python.org>
Sent: Thursday, February 07, 2002 16:55
Subject: Re: [NEWBIE] ftplib again...


> > 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)

Thanks loads Steve...that was perfect. I coulda sworn I tried that
particular construct after seeing it in some sample code (ftpmirror.py, I
think) and it didn't work then...but hey...it works...8-)

Thanks
bkd





More information about the Python-list mailing list