D. J. Bernstein
Internet publication
FTP: File Transfer Protocol

The CWD, PWD, and CDUP verbs

The server keeps track of a name prefix for the client. The name prefix is a pathname; it always begins with a slash.

The name prefix is initially a server-defined function of the username. It may be changed by CWD and CDUP requests.

The name prefix allows the client to abbreviate encoded pathnames in parameters for various requests.

The CWD verb

A CWD request has a nonempty parameter giving an encoded pathname. It asks the server to set the name prefix to this pathname, or to another pathname that will have the same effect as this pathname if the filesystem does not change.

The server may accept a CWD request using code 200 or 250:

     CWD /public
     250 Okay.
(RFC 959 says that code 250 is required, but also gives examples of code 200. I recommend 250.)

The server may reject a CWD request using code 550:

     CWD /pubilc
     550 /pubilc: No such file or directory.
Most servers reject CWD requests unless the pathname refers to an accessible directory. Some servers accept all CWD requests, without regard for what directories are actually accessible.

RFC 1123 requires that the server treat XCWD as a synonym for CWD.

The PWD verb

A PWD request asks the server to print the name prefix:
     PWD
     257 "/home/joe"

If the server accepts the PWD request (required code 257), its response consists of exactly one line, with text in the following format:

  1. a double quote;
  2. the name prefix, with each double quote replaced by a pair of double quotes, and with \012 encoded as \000;
  3. another double quote;
  4. a space;
  5. useless human-readable information.
Many servers fail to check for double quotes in the name prefix. There is no reliable way for the client to compensate for this.

Servers are permitted to reject PWD requests with code 550, but high-quality servers will try to accept all PWD requests.

RFC 1123 requires that the server treat XPWD as a synonym for PWD.

The CDUP verb

A CDUP request asks the server to remove the last slash, and everything following it, from the name prefix. If this produces an empty name prefix, the new name prefix is a single slash. CDUP parameters are prohibited.

The server may accept a CDUP request using code 200 or 250. (RFC 959 says that code 200 is required; but it also says that CDUP uses the same codes as CWD.) The server may reject a CDUP request using code 550.

RFC 959 envisioned CDUP as a means of undoing a previous CWD, to simplify namespace navigation:

     PWD
     257 "/home/joe"
     CWD tex
     250 Okay.
     PWD
     257 "/home/joe/tex"
     CDUP
     200 Okay.
     PWD
     257 "/home/joe"
However, this is horribly unreliable in practice. Here is a typical example from a UNIX server where there is a ``symbolic link'' from /bin to /usr/bin:
     PWD
     257 "/" is current directory.
     CWD /bin
     250 CWD command successful.
     PWD
     257 "/usr/bin" is current directory.
     CDUP
     250 CWD command successful.
     PWD
     257 "/usr" is current directory.
I strongly recommend that clients avoid CDUP.

RFC 1123 requires that the server treat XCUP as a synonym for CDUP.