Distinguish file and folder on ftp site

Fredrik Lundh fredrik at pythonware.com
Thu Aug 14 04:08:48 EDT 2008


Mailing List SVR wrote:

> is there a simple way to do this?
> 
> ftplib seems unable to distinguish between files and dir, a mimetype
> check would be good,

the FTP protocol doesn't specify the format for the output from the LIST 
command, so you have to use some heuristics; see e.g. the code in

http://svn.python.org/projects/python/trunk/Tools/scripts/ftpmirror.py

or use a wrapper for Dan Bernstein's ftpparse library (requires a C 
compiler):

     http://cr.yp.to/ftpparse.html
     http://c0re.23.nu/c0de/ftpparsemodule/
     http://effbot.org/downloads/#ftpparse

Not sure what you mean by "mimetype"; that has nothing to do with 
directories vs. files, afaik.

</F>




More information about the Python-list mailing list