Subject: Ftp-WG: NLST vs MLSD

From: Frank da Cruz <[email-masked]>
Date: Tue, 8 Oct 2002 16:46:25 -0500

Replying to a reply from Alun Jones to a message from me about MGET...

> At 10:56 AM 10/3/2002, you wrote:
> >As specified, MLSD is sufficiently unnatural to have caused the following:
> >
> >  1. My first implementation simply assumed that the server would treat
> >     incoming filespecs just like NLST did.  Yes, I should have read it
> >     more closely.
> 
> NLST and MLST both specify a single filename that represents a directory 
> "or other system-specific file group descriptor" (you _could_, I suppose, 
> take that to mean a wild card specification, but that's setting your 
> reading to match your opinion, rather than the other way around.)
> 
Right, everybody says this and I agree in principal, but the fact is that
every command-line FTP client since the beginning of time has sent wildcards
to the server in the NLST command, received back a list of matching files,
and then RETR'd each file in the list, with no matching of the list against
a locally-held copy of the wildcard, or any expecation that such matching
was needed.

Everybody says that Postel, et al, did not intend this, which might well
be true, yet server-side expansion of NLST wildcards is current practice --
not just in Unix but as far as I can tell, everywhere: VMS, TOPS-20, VM/CMS,
you name it.

> >  2. My first implementation worked as expected against the two server
> >     implementations I could find: Ipswitch and NetBSD.  Apparently the
> >     other implementors made the same assumptions I did.
> 
> Apparently two other implementors added functionality that matched your 
> assumption.  Tell me - what do they do when you provide a wildcard that 
> produces results in more than one directory?  What do they list as cdir, 
> pdir, etc?  Can you predict this and rely on the answer?
>
I doubt it!  As is clearly evident in the real world; specs are one thing,
implementations another.  Since software development is uncontrolled, the
only way to write a client that "just works" these days is to experiment
with every existing server, catalog its quirks, and program around them.

In any case, my concern is that the new spec conflicts with existing
practice.  For decades it has been possible for FTP clients to execute
commands like:

  mget pics/mae-west-*.jpg

or even:

  mget pics*/mae-west-*.jpg

or:

  mget pics/*/mae-west-*.jpg

and get at least a semi-expected result.  This is about to change.

> >In other words, server-side wildcard expansion is what people expect.
> 
> Yes, but it's not what is documented.  People expect that their computers 
> will understand what they mean rather than what they say, and they get 
> frustrated when the opposite is true.  Expectations should be met where it 
> is reasonable (and possible) to do so, but features should not arrive 
> simply by accident - they should be specified.
> 
Agreed, and I also agree the previous specification could not have been
sufficiently clear if everybody misimplemented it.

> >I had another minor quibble with them about the pitfalls of doing
> >recursive MGETs under their model, but it's more theoretical than practical,
> >and won't matter unless downloading a VERY deep directory (and, in a pinch,
> >can be programmed around in the client, though I wouldn't like to do it).
> 
> Recursive descent of subdirectories is a messy issue in any system.  But 
> very necessary for mirroring and backup purposes.  In such a situation, of 
> course, wild cards would likely be less used, and the directories would 
> usually be downloaded in full (in which case, the relative size of the 
> listing as compared to the files would generally be small).
> 
I don't think it's our business to decide what recursion will be used for.
Users can be creative; why limit their choices?  I can think of all sorts of
scenarios where I might want get a directory tree with certain files included
(e.g. source code) but not other files (e.g. object modules).

I also do not agree, as some suggest, that directory trees or other
collections of files should just be "zipped up" and transferred all in
one piece.  Not all platforms support zip, gzip, bz2, tar, etc, and even
when they do, the Zipped (or whatever) files, when unzipped on a different
platform, are likely to have the wrong record format or character set.

Thus the file transfer client/server pair have to deal with directory
structure, file record format, the text/binary distinction, even text-file
character sets themselves.

> MLSD has the concept of "current directory", which certain wildcard 
> expansions make void.  Now, we _could_ say that we only support wildcard 
> expansions of file names, but then one of the curious selling points of our 
> software in certain markets is that wildcard expansions happen at all 
> points along a file path.  If I implement wildcard expansions in MLSD, I 
> want it to be done by following the standard, not by mimicking the way some 
> random operating system does it, and hope that this becomes the de-facto 
> standard, as it did with NLST.
> 
Clearly it deserves some serious thought; that's what we're for.

> >The real point is that "who expands wildcards" has a fundamental impact
> >on the user, as noted in my paper.  Once FTP servers and clients start
> >supporting MLSD alongside NLST, countless FTP command-line client users
> >will get nasty surprises and will have to be "educated" to accommodate
> >themselves to new complexities dictated by network protocols that they
> >should not have to worry about.
> 
> I'd have thought that most command-line client users would be comfy with 
> LIST for regular directory listings, since that _is_ supposed to be a 
> user-readable format, not machine-readable, and that MGET would be 
> implemented through NLST.  You obviously use other commands around your 
> MGET implementation to provide information such as the file size and date, 
> and I can appreciate that you might not want to download a list of many 
> thousands of files (though how many users have such a directory designed to 
> be accessible through FTP over slow modem lines?), or run these commands 
> several times.
> 
Well, I'm totally nauseated at the idea of the FTP client itself using the
LIST output from the server to construct a file list for MGET or for GUI
clicking by parsing who-knows-how many platform-specific directory listing
formats, especially the silly Unix one with its impossible date/time
formats.  The MLST format for machine-readable file lists should have been
part of the FTP spec from the beginning.

The question at hand is do we have to change the fundamental relationship
between FTP client and server in order to get the very nice and handy MLST
file-list format?

(I'm alluding to, rather than restating, specific issues I listed in the
"newftp" paper on the Kermit website.)

> >Since server-side wildcard expansion has been the norm for decades, I think
> >that any new protocol to replace NLST should be compatible in behavior by
> >default in this respect.  That's a basic principle of software engineering.
> 
> It's never been discussed or debated, AFAICT.  Server-side wildcard 
> expansion happened, not because the RFC mandated it, but because the FTP 
> server authors on Unix couldn't be bothered to repeat the 'ls' code, and 
> simply called out to the executable (which, incidentally, is why even a 
> chrooted FTP server on Unix _must_ have a 'bin' directory containing 'ls', 
> and an 'etc' directory containing 'passwd').  If wildcards are to be 
> supported, it _must_ be by specification, not by simple adoption of the 
> most popular accidental implementation.  (We can all guess whose 
> implementation would be adopted in such a case, and it's unlikely to be the 
> best engineering solution.)
> 
As noted in my paper, server-side wildcard expansion has certain benefits
that we have all become accustomed to:

 . The size of the file lists returned by an MGET request are controlled
   by the user, by tuning the wildcard (in the "mae-west*.jpg" example
   above, suppose these pictures were in a directory that contained
   a million files, but you only wanted three of them).

 . The wildcard filespec to obtain a certain group of files is the same
   for all clients and users.  Thus the FTP site admin can give a simple
   one-line formula for getting the files.  They can even arrange their
   FTP site (e.g. by file naming conventions) that allow easy selection
   of groups of files by wildcard.

 . Certain platforms or FTP servers have unique capabilities that you
   might want to take advantage of if you know what they are.

> >Client-side wildcard expansion is a big change and should be a conscious
> >choice of the user, not a surprise.
> 
> On the other hand, of course, it could make the user's experience more 
> comfortable - why should a user of operating system ABC be aware of 
> wildcard expansion syntax on every FTP system he uses?  A standard 
> wild-card format could replace that, of course, and still allow the server 
> to do the expansion for the client.
> 
That's a topic for another day.  For now, there is no standard wildcard
format, not even within one platform (with a few exceptions).  In Unix, for
example, every program that expands wildcards does it its own way, either
with its own custom code, or by calling some nonstandard library or other.
Thus even on the same computer, different applications use different
wildcard syntax.

> >To put it another way, if MLSD had been simple plug-in replacement for
> >NLST that returned the file list in a better format, we'd have a better
> >situation.  As matters stand, it has too many "riders" attached to it to
> >make it attractive to implementors, except maybe in the GUI world.
> 
> I think that's what it was mostly designed for.  Apparently there wasn't 
> enough representation in the command-line world.
> 
Call me Mr. Command Line :-)

> >There's nothing wrong with promoting GUI FTP as long as you don't do it
> >by changing the procedural aspects in ways that make more advanced usage
> >impractical, since after all, it's the advanced users who are responsible
> >for all that content that mass-market consumers click on.
> 
> Rather than have fiascos such as the RFC-standard FTP URL format that has 
> significant incompatibilities with the way _everyone_ has implemented it, 
> it's important to codify whatever's going on.  Wildcards, where they are 
> supported, must be documented prior to implementation, not the other way 
> around.
> 
Agreed.  There should be no guesswork about who expands them.  And heaven
forbid we get into a situation where the client assumes the server does,
and the server assumes the client does.  As to their syntax and semantics,
I think that's way beyond us.

- Frank

---

From: Alun Jones <[email-masked]>
Date: Wed, 9 Oct 2002 23:17:50 -0500

>with every existing server, catalog its quirks, and program around them.

Does each MLSD output for a wildcard spec even produce a 'cdir' 
type?  After all, the wild card isn't going to match a directory, usually, 
yet 7.3.1 of the MLST draft notes that an MLSD response MAY include one or 
more "cdir" type entries, probably because the authors anticipated that 
MLSD's argument would always be a directory that would be listed in that 
'cdir' entry.  "MLSD *.txt" could produce a line that's of 'cdir' type, and 
whose name definitely doesn't match "*.txt".

In the instance that an FTP server allows "MLSD */*.txt", it may even be 
useful to define that a 'cdir' entry should be listed prior to the files 
that match the wildcard spec in its directory.  So that if "*/*.txt" 
matches "a/1.txt", "a/2.txt" and "b/3.txt", you'd have a 'cdir' line that 
specified where 'a' is, followed by listings for "1.txt" and "2.txt", then 
a 'cdir' line for 'b', and a listing for "3.txt".

This goes against the note in 7.3.1 that the 'cdir' entry can occur 
anywhere in the MLSD output, because it would require that the 'cdir' line 
precede all matched elements in that directory.  Would it be worth 
specifying that all 'cdir' output lines must precede other lines relevant 
to that directory?

Here's another thought - what should MLSD do if given a wildcard that 
expands into several names, some of which are directories, others of which 
are files?  Should it list the details of the directories, or the contents 
of those directories?

We either need to specify these sorts of answers, or require that MLSD not 
be used with wildcards.  As you point out, it's too important to rely on 
people fudging it through by successively refining implementations.  It 
needs to be specified this time.

>and get at least a semi-expected result.  This is about to change.

Hardly - NLST isn't going to go away.  It is still expected that NLST will 
be used for MGET.  What you're hoping to do is to _use_ MLSD to get facts 
about those files before transferring them, so that you don't have to do a 
SIZE, MDTM, etc, for each file that you transfer (you could just do an 
MLST, but I can see why you'd like an MLSD with wildcards).

>with its own custom code, or by calling some nonstandard library or other.

Actually, to judge from the recent problems with "../*/../*" overloads, 
they mostly use glob() from libc.

Alun.
~~~~

--
Texas Imperial Software   | Try WFTPD, the Windows FTP Server. Find us at
1602 Harvest Moon Place   | http://www.wftpd.com or email [email-masked]
Cedar Park TX 78613-1419  | VISA/MC accepted.  NT-based sites, be sure to
Fax/Voice +1(512)258-9858 | read details of WFTPD Pro for NT.

---

From: "D. J. Bernstein" <[email-masked]>
Date: Sat, 12 Oct 2002 15:35:23 -0500

Frank da Cruz writes:
> For decades it has been possible for FTP clients to execute commands like:
>   mget pics/mae-west-*.jpg

And it's still possible. If you receive that command from the user,
simply switch to the pics directory, do an NLST, extract the mae-west-*
names, and retrieve those files one by one. What's the problem?

Are you saying that your client tries to push the * processing over to
the server? Sorry, but that isn't guaranteed by the FTP standard, and it
isn't supported by all servers. You should be using the standard NLST
mechanism instead.

The UNIX ftpd and its offshoot wuftpd have, historically, accounted for
most FTP servers on the Internet, but you shouldn't be relying on their
wildcard quirks. There have always been servers that, quite reasonably
and in full compliance with the protocol, don't imitate ftpd's wildcard
processing. You would already know this if you had tested your client
more thoroughly.

By the way, this is orthogonal to the question of list format.

> (in the "mae-west*.jpg" example

Reality check: What kind of idiot organizes his files that way? Do you
realize how long it takes for a server to look through a million-file
directory on a typical filesystem? Have you heard of subdirectories?

---D. J. Bernstein, Associate Professor, Department of Mathematics,
Statistics, and Computer Science, University of Illinois at Chicago

---

From: Alun Jones <[email-masked]>
Date: Sat, 12 Oct 2002 19:34:01 -0500

>directory on a typical filesystem? Have you heard of subdirectories?

Yes, I've seen it happen, I'm afraid.  It was a file server for an NMR 
machine.  An absolutely horrible, and totally inefficient layout, as you 
say.  I don't think it's worth making an effort to support such bad behaviour.

Alun.
~~~~