ftplib and 'LIST' command :

Michael Gilfix mgilfix at eecs.tufts.edu
Thu Aug 1 14:38:10 CEST 2002


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.

  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.

                   -- Mike

-- 
Michael Gilfix
mgilfix at eecs.tufts.edu

For my gpg public key:
http://www.eecs.tufts.edu/~mgilfix/contact.html




More information about the Python-list mailing list