What no FTP?

New Articles

Clean up Spilled Tar.

The case of the missing errors.

Progress bar for File Uploads

Stuck with out an FTP client? Here's what to do.

So you need to FTP into a server in hurry but don't have an ftp client at hand? Don't let that stop you. Telnet is a worthy substitute.

The first step is to make an ftp connection, this can be done by the command telnet ftp.myserver.com 21
if your server (replace ftp.myserver.com with your own) supports ftp you would see something similar to the following.

	Escape character is '^]'.
	220 (vsFTPd 1.1.3)
Port 21 is obviously the port for FTP. The second step is to send in your username and password. In the discussion that follows, the '<' symbol prefixes commands that you type in and the '>' symbol denotes the server response.

Here's how you login


< USER raditha
> 331 Please specify the password.
< PASS 123
> 230 Login successful. Have fun.

The major point worth noting is that if your login is successfull you will recieve a status code of 230 followed by a welcome message.

Unlike HTTP which works over a single port (80) ftp works on two different ports. The first first one port 21, to which we telneted to is known as the control connection and the second one is known as the data connection.

The data connection can either be on port 20 when you use the PORT command or on a randomly chosen port when you use the PASV commmand. We will only look at the PASV command here. So to get back to your telnet session just type in PASV at the command prompt

< PASV
> 227 Entering Passive Mode (127,0,0,1,54,255)

The response message includes three vital pieces of information, the first, the status code 227 tells you that can use passive mode. the data with in the brackets tells you which IP and port you should use for your data connection. The first 4 digits contain the IP and the last two digits contains the high and low order bits for the port.

If your computer does not have a calculator program you may need pencil and paper to calculate that 54,255 corresponds to 14079. The number is a randomly chosen unused port number. Now you can establish a second telnet connection on this port.

telnet ftp.myserver.com 21

Now we will try to get a listing of files available on the ftp server. Go back to your control connection and type in LIST. You will see the output on your data connection. It's that simple. Next week we will see how we can make use of this idea to scratch together a simple FTP client using PHP.

That's all for now. Have a cup of tea and then read these articles:
Making an FTP client with PHP.
Backgrounder on FTP Security.