Oberon || Library || Module Index || Search Engine || Definition || Module


Ulm's Oberon Library:
FTPUnixDirLister


NAME

FTPUnixDirLister - list UNIX directories for FTP

SYNOPSIS

CONST regular = 0; directory = 1; symlink = 2; other = 3;


PROCEDURE GetFileType(pathname: ARRAY OF CHAR; VAR ftype: SHORTINT; errors: RelatedEvents.Object) : BOOLEAN; PROCEDURE GetSize(pathname: ARRAY OF CHAR; VAR size: LONGINT; errors: RelatedEvents.Object) : BOOLEAN; PROCEDURE GetTimestamp(pathname: ARRAY OF CHAR; VAR timestamp: ARRAY OF CHAR; errors: RelatedEvents.Object) : BOOLEAN;

PROCEDURE List(s: Streams.Stream; pathname, relpath, pattern: ARRAY OF CHAR; long: BOOLEAN; errors: RelatedEvents.Object) : BOOLEAN;

DESCRIPTION

FTPUnixDirLister offers some auxiliary functions for handlers of some FTP commands that list the contents of a directory or retrieve file properties.

GetFileType returns a simplified file type of pathname. Files of type other should usually neither be accessed nor shown by FTP services.

GetSize returns the size of pathname in bytes under the assumption of a binary transfer mode. GetTimestamp returns, in conformance to FTPCommands.mdtm, the time of the last modification of pathname in the form YYYYMMDDHHMMSS.

List prints to s,

Lines output resemble that of ``/bin/ls -la'' if long is set to TRUE, and to ``/bin/ls'' otherwise. However,

The original pathname in pathname is never revealed. Instead relpath is printed, if given, and, in case of a directory listing, the filename inside a directory is provided. The wildcard pattern pattern is, if given for a directory, matched against filenames inside of directories and works as filter. Wildcard patterns are interpreted by ScanDir but locally only against filenames found inside the directory specified by pathname. Multi-level patterns like ``*/*'' do not work.

All occurences of newlines in directory entries are replaced by null bytes when being output to s.

EXAMPLE

A directory containing a regular file called textfile, a sub-directory called subdir and a symbolic link link to textfile would be shown as:
drwxr-xr-x   3 0            512 May  7 13:51 .
drwxr-xr-x   3 0            512 May  7 13:51 ..
-rw-r--r--   1 0              7 May  7 13:51 textfile
drwxr-xr-x   2 0            512 May  7 13:51 subdir
lrwxrwxrwx   1 0              8 May  7 13:51 link -> textfile
The same directory as shown by /bin/ls -la:
total 10
drwxrwxr-x   3 afb      sai          512 May  7 15:51 .
drwxrwxr-x   3 root     root         512 May  7 15:51 ..
lrwxrwxrwx   1 afb      sai            8 May  7 15:51 link -> textfile
drwxrwxr-x   2 afb      sai          512 May  7 15:51 subdir
-rw-rw-r--   1 afb      sai            7 May  7 15:51 textfile

DIAGNOSTICS

All procedures return FALSE in case of errors and relate all error events to errors but do not generate any error events on themselves. GetSize and GetTimestamp return results for valid regular files only.

SECURITY CONSIDERATIONS

All path names coming from the FTP client should be checked by FTPUnixPaths.CheckAndProcessSymLinks before passing them directly to any of these operations. Otherwise, the pseudo chroot jail is not effective, see FTPUnixPaths.

The directory listings by this module do not rely on any external programs (like /bin/ls) but provide, to stay compatible with a large number of FTP clients, listings that look like those generated by /bin/ls except that

SEE ALSO

FTPUnixFileSystems
uses this module to implement the related FTP commands.

BUGS

The directory listings are not sorted. Unicode is not supported yet.
Edited by: borchert, last change: 2001/05/07, revision: 1.3, converted to HTML: 2001/05/07

Oberon || Library || Module Index || Search Engine || Definition || Module