ftpparse (version 0.93)
index
/usr/local/lib/python2.1/site-packages/ftpparse.so

Provides access to ftpparse function and assosiated constants.
 
From Dan Bernstein's ftpparse page at http://cr.yp.to/ftpparse.html
 
---8<---------------------------------------------------------------
 
ftpparse is a library for parsing FTP LIST responses.
 
ftpparse currently understands the LIST output from any UNIX server,
Microsoft FTP Service, Windows NT FTP Server, VMS, WFTPD, NetPresenz,
NetWare, and MS-DOS. It also supports EPLF, a solution to the
LIST-parsing mess.
 
ftpparse parses file modification times into time_t, so you can easily
compare them and display them in your favorite format. It lets you
know how precise the time_t is: LOCAL meaning exact with known time
zone (available from EPLF), REMOTEMINUTE meaning unknown time zone and
seconds, or REMOTEDAY meaning unknown time zone and time of day.
 
To use ftpparse, simply feed each line of LIST output to the
ftpparse() routine, along with a pointer to a struct ftpparse. If
ftpparse() returns 1, you can find a filename and various other useful
information inside the struct ftpparse.
 
Commercial use of ftpparse is fine, as long as you let me know what
programs you're using it in.
 
---8<---------------------------------------------------------------
 
This Python module is based on Dan Bernstein's ftpparse
library at http://cr.yp.to/ftpparse.html Mr. Bernstein requests you to
inform him if you use his library in an commercial application.
 
It extends Bernstein's ftpparse code by providing a way to detect
symbolic links on some UNIX Servers.
 
You can get the version of the actual module you are using by 
querying '__version__' and '__rcsid__'.
 
The Python wrapper was hacked by drt@un.bewaff.net - http://c0re.23.nu/
 
You might be able to find more Information and updates at
http://c0re.23.nu/c0de/ftpparse/

 
Functions
            
ftpparse(...)
Parsing of FTP Server responses.
 
ftpparse should be called with a list of lines obtained from an
FTP-Server. It returns a list of parsed filenames. If ftpparse can't
find a filename it will fill the corospondending entry in the output
list with None. If it can find a filename it returns a 10-element tupe
with Information about the entry.
 
(name, size, sizetype, mtime, mtimetype, cwd, retr, id, idtype, islink)
 
'name' is the name of the file.
 
'size' is the number of octets, if 'sizetype' is SIZE_BINARY this can
 be interpreted asw binary size, if sizetype is SIZE_ANSII it can be 
interpreted as ASCII size. If ftpparse can't decide sizetype is 
SIZE_UNKNOWN.
 
'mtime' is the modification time of the file. If mtimetype is MTIME_LOCAL it
can be assumed that the time is correct. If mtimetype is
MTIME_REMOTEMINUTE time zone and secs are unknown, if mtimetype is
MTIME_REMOTEDAY time zone and time of day are unknown.
When a time zone is unknown, it is assumed to be GMT. You may want
to use localtime() for LOCAL times, along with an indication that the
time is correct in the local time zone, and gmtime() for REMOTE* times.
 
If cwd is '1' it can be assumed that the file is a directory, if it is '0' 
the FTP CWD command is definitely pointless. 
 
If retr is '1' it can be assumed that the file can be retrived, if it is 
'0' the FTP RETR command is definitely pointless.
 
If 'id' is set the file can be accessed by an unique ID. This feature is 
to my knowledge only supported by Dan Bernstein's FTP servers. If idtype 
is ID_FULL there is really an unique identifier for files on this FTP server.
If idtype is ID_UNKNOWN nothing is known about the ID.
 
If 'islink' is set to one it can be assumed that the filename is a symbolic 
link pointing to another file. 
 
The module defines the constants NAME, SIZE, SIZETYPE, MTIME, MTIMETYPE, CWD, 
RETR, ID, IDTYPE and ISLINK to allow acces to the individual return valuse.
 
Example:
>>> import ftpparse
>>> ls = ['-rw-r--r--   1 root     other        531 Jan 29 03:26 README',
...       'dr-xr-xr-x   2 root     other        512 Apr  8  1994 etc', 
...       'Total of 11 Files, 10966 Blocks.']
>>> ftpparse.ftpparse(ls)
[('README', 531, 1, 980738760, 2, 0, 1, None, 0), ('etc', 512, 1, 765763200, 3, 1, 0, None, 0), None]
>>> for x in ftpparse.ftpparse(ls):
...   if x and x[ftpparse.MTIMETYPE] == ftpparse.MTIME_REMOTEMINUTE:
...     print x
... 
('README', 531, 1, 980738760, 2, 0, 1, None, 0)

 
Data
             CWD = 5
ID = 7
IDTYPE = 8
ID_FULL = 1
ID_UNKNOWN = 0
ISLINK = 9
MTIME = 3
MTIMETYPE = 4
MTIME_LOCAL = 1
MTIME_REMOTEDAY = 3
MTIME_REMOTEMINUTE = 2
MTIME_UNKNOWN = 0
NAME = 0
RETR = 6
SIZE = 1
SIZETYPE = 2
SIZE_ASCII = 2
SIZE_BINARY = 1
SIZE_UNKNOWN = 0
__file__ = '/usr/local/lib/python2.1/site-packages/ftpparse.so'
__name__ = 'ftpparse'
__rcsid__ = '$Id: ftpparsemodule.c,v 1.5 2002/01/18 10:15:51 drt Exp $'
__version__ = '0.93'