ftp and lowercase?

David Bolen db3l at fitlinxx.com
Mon Jul 31 18:05:35 EDT 2000


Stein Surland <ssurland at online.no> writes:

> The host did not take the LIST command so I changed it to LS and ls. It
> seems that the ftplib sends the list command in uppercase. How to change
> this to lowercase? I have ftp'ed to the host and it does not recognize
> LIST or LS only ls.

(I know that you resolved your issue later, but just an FYI)

Note that neither "LS" nor "ls" are valid FTP commands for use with a
server.  The commands for retrieving directory information are "LIST"
(name plus server-specific information) or "NLST" (name only).  The
commands - although often transmitted in uppercase - are case
insensitive (as long as the server conforms to the protocol).

What you were probably running into is that when you use "ls" in FTP
clients that support that command, they internally translate that into
a remote "LIST" command.  And often such clients (particularly those
modified from a Unix base) are case sensitive in parsing their command
lines.  In some clients you can enable debugging (e.g., "debug" or
something similar) and see the underlying commands being transmitted
in response to your entered commands.

ftplib exposes a reasonably raw interface to the FTP client/server
stream, so you need to work in terms of the real FTP protocol
commands, and not some of the command aliases that ftp clients may
implement.

You can get more information about the commands and how they work if
interested by reading the protocol specification (RFC959, or STD9),
available in any RFC repository (http://www.rfc-editor.org for one).
Section 4 covers the commands.

In your example, the reason you had problems is that placing a space
after the LIST command indicated that you were going to supply a
directory path that you wanted a listing of (see section 5.3.1 of the
spec).  So you were in violation of the spec for ending the command at
that point.  While I expect some (many?) servers would treat that as
no directory a bit more gracefully, rejecting the command is also valid.

--
-- David
-- 
/-----------------------------------------------------------------------\
 \               David Bolen            \   E-mail: db3l at fitlinxx.com  /
  |             FitLinxx, Inc.            \  Phone: (203) 708-5192    |
 /  860 Canal Street, Stamford, CT  06902   \  Fax: (203) 316-5150     \
\-----------------------------------------------------------------------/



More information about the Python-list mailing list