ftplib and 'LIST' command :

Steve Holden sholden at holdenweb.com
Fri Aug 2 11:42:49 EDT 2002


"Michael Gilfix" <mgilfix at eecs.tufts.edu> wrote, perhaps a little
misleadingly ...
> On Thu, Aug 01 @ 10:36, jack wrote:
> > how, with the 'LIST' command,  can i find the name of each directory and
> > each file? (in a list, tuple or other)
> > does I have to parse the response of the server? (the format of the
> > response is always different)
> > I will want for example to obtain a list of the directories and another
> > of the files, for the current directory.
>
>   Sadly, yes. Under the hood of the ftp control session is really just
> a telnet session. When you invoke the list command, a 'LIST' is sent
> and the response sent by the server is what you get. However, most ftp
> sites follow a pretty standard format and it's pretty easy to parse
> the fields with regex's and do matching logic.
>
This makes it sound as though the Telnet protocol is used by FTP clients,
which is very far from the truth. I suspect that what Michael is trying to
say is that the listing output is generated by the server, not the client,
and so yes, you must expect to parse it to discover the directory structure
of the area of the FTP server's filestore which interests you.

>   If you want an example in python, check out the RemoteWin in class
> in filewin.py in CVS at http://www.sourceforge.net/projects/ftpcube.
> While the client doesn't handle MS servers yet, there aren't too
> many of them out there.
>
If you have a full distribution (the Windows binary doesn't include it) you
can also look for ftpmirror.py in the Tools subdirectory. This program does
a fairly complete analysis of FTP directory listings, and will give you many
clues as to how to proceed.

regards
-----------------------------------------------------------------------
Steve Holden                                 http://www.holdenweb.com/
Python Web Programming                http://pydish.holdenweb.com/pwp/
-----------------------------------------------------------------------








More information about the Python-list mailing list