ARTICLE

The FTP protocol
Contributed by Girish Venkatachalam in Servers on 2007-09-17 12:21:13
The file transfer protocol in short known as FTP has been around since the early days of the Internet. And several decades hence, even today ftp is a common way of downloading files from the Internet.

We even use it within our LAN for obtaining ascii and binary files. This article attempts to give an overview of how the protocol works and also point out why this protocol creates problems with modern Internet realities like NAT and firewalls.

FTP is an application layer protocol layered on top of TCP. It uses TCP port number 21. But that is not all. Unlike any other protocol, it uses TCP port number 20 at which it listens for incoming connections. The TCP connection to port 21 of the FTP server is the command channel. And whenever you list files or transfer files back and forth, a brand new TCP connection is established from the FTP server to the FTP client machine. This is called the data channel.

All this complexity of two TCP connections and inbound connections serve no purpose. We could jolly well have used one single connection both for data and commands.

Today we are familiary with the marvellous ssh program which multiplexes several TCP and X11 connections over a single TCP connection to port 22. Anyway it is impossible to change FTP now. It is too old and widespread to even attempt such a thing. But in spite of this overly complex design, the protocol does perform well and is quite efficient in doing its job of transferring files from and to a remote machine on the Internet.

Here is a pictorial representation of the FTP protocol.

As you can see, I was referring to the active mode of FTP above. Today many servers support passive mode FTP in which an inbound connection is avoided. People hate someone connecting from outside. And firewalls certainly will not allow.

This brings us to the topic of FTP and firewalls. There is a thrid party server to server transfer mode in FTP in which you can transfer files between two FTP servers. As you can see, this complicates FTP interactions even further and from the security point of view , FTP is perhaps the most dangerous protocol. Did I tell you that the username and password are sent in the clear?

Like all protocols FTP has evolved over time, but the core remains the same. Today NAT devices also detest FTP protocol as they have to specially handle the incoming FTP connection in active mode.

With all this FTP is here to stay. Even with extremely robust p2p protocols like bittorrent in today's Internet landscape, FTP will continue to be used for transferring files.

Files are sent in the clear of course. And there is no support for integrity checking. There are extensions which support many things.

sftp, the companion program of ssh gives a FTP like interface. But internally it is completely different. Not only is it secure, as it is encrypted with sound authentication mechanisms, the wire protocol also is completely different.

There are secure alternatives to FTP which add an SSL layer below. But given the nature of the protocol as I have talked in enough detail above, this is not trivial.

File transfer in today's Internet and future is not going to be client server. With VoIP and other person to person communcations gaining ground, files will be shared in different ways and p2p model will win in the end. This ensures redundancy, better bandwidth utilization and is a form of fault tolerant distributed computing.

There are popular FTP clients and servers in the linux world some of which are certainly worth mentioning.

pure-ftpd
proftpd
ncftp
lftp
are some examples. ncftp comes with ncftpget and ncftpput which take the URL format for passing username and password. I shall give an example that can help you started. This can help you script FTP easily.
$ ncftpget ftp://user:password@server:/dir/file

Have fun!


 
Discussion(s)
Nice one
Written by S.Ajesh kumar on 2007-09-18 22:11:46
Dear girish,
the article on Ftp is a useful one .why don't u cover some of the security features of Ftp in Linux systems.Hope that u would surely give it in future.I think in most of the linux machines if u login remotely as root(ftp),u can access all the areas of the system.isnt it? how to protect it?
Ajesh
Discuss! Reply!

Nice one
Written by Thaha on 2007-09-19 06:10:07
thanks for such a nice article.
Discuss! Reply!

Test Engineer
Written by Geanthy on 2007-09-19 07:27:42
Keep publishing articles like this for us newbies
Discuss! Reply!

THX
Written by NeonGen on 2007-09-22 13:01:32
This article gave me some inside thx
Discuss! Reply!

more on ftp
Written by Andrei Stoleru on 2007-10-07 12:23:18
Hi
Nice tutorial.
This reminds me: I'm trying to write a ftp client in Flex (with the new socket class in as 3.0), any idea where I can read about all the commands/responses from a ftp serve?
Thanks ;)
Discuss! Reply!

help needed
Written by mahesh on 2007-10-10 12:34:05
Quote:

Hi
Nice tutorial.
what is vsftpc and how its related to FTP
Discuss! Reply!

Difference between FTP payload Data and
Written by Irfan Ahmed on 2007-11-06 06:14:00
what is the difference between simple FTP payload data and chopping a file into payload size. Both contains same data.

do FTP changes data in any means during the transfer which later handles in application or transport layer.

Discuss! Reply!

Linux Noob
Written by X-Modius on 2007-11-16 08:41:18
Informative article. Perhaps you could next go into more depth on SFTP with SSH. Hooray for OpenSSH.com, a free download of the secure SSH daemons for creating your own secure FTP site. :)

No I'm not from the group, but I'm a noob and found it easy to set up (in Windows). Please don't stone me. :) Linux is next.
Discuss! Reply!

consultant
Written by John on 2007-12-02 00:35:34
Thank you for nice article! :)
In addition to the clients that you listed don't you know anything about linux ftam ftp client working over IP networks? There are some implementations but rather old and I can't get it working (contacts to authors don't work any more etc.). Any information incl. contacts are highly appreciated. Thank you so much.
Discuss! Reply!

networking doubt
Written by ravikumar on 2008-04-08 14:24:08
hi iam ravi kumar

i had a doubt on checksumming a packet..

can i have your mail id to which i can contact with my doubt..
Discuss! Reply!