edtFTPnet/Free - Open-source FTP component for .NET | Download
 Sample Scenarios

Example 1

For example, to change directory the client sends:

> CWD dirname

The server responds with:

250 CWD command successful

As the reply begins with a ‘2’, we know the command sequence is completed.

However if we attempt to change directory to one that does not exist:

> CWD nonexistentdir

The server responds with:

550 nonexistentdir: The system cannot find the file specified.

As the reply begins with a ‘5’ we know that the command failed.




Example 2

To transfer a text file, we issue a ‘RETR’ command to the server.  However to transfer the file we require a data connection to be set up. This can be done using active or passive mode.

As discussed previously, in active mode, the client sends a ‘PORT’ command, indicating what address and port number the server should connect to:

> PORT 192,168,10,1,4,93

The first four digits are the IP address, and the last two encode the port number (in two 8-bit fields, the first being the high order bits of the 16-bit port number).

The server responds with:

200 PORT command successful.

This indicates that the data connection has been established.



Next, the ‘RETR’ command is issued:

> RETR abc.txt

The server responds with:

150 Opening ASCII mode data connection for abc.txt(70776 bytes).

The reply begins with a ‘1’, so we know that the command was successful, but the server will be sending another reply – the client cannot issue another command until this is received.

Eventually, the server sends:

226 Transfer complete.

The command sequence is complete, the file has been transferred, and the client can issue another command.

See RFC 959 for details about the second digit, and more extensive examples.

Note that most standard command-line FTP clients support debug mode, which displays the FTP commands that are being sent to the server, and the reply strings that are received back. Typing “debug” at the prompt will usually put the client into debug mode.


Next: Data Types