Here is a header to retrieve an MP3 file from a HTTP server:
GET /whateverdir/themp3.mp3 HTTP/1.1
Host: whateverhostname.com
The server then returns a header if the file is found:
HTTP/1.1 200 OK
The rest of the return is the actual mp3 data. And we are done.
For FTP, same file, first has to connect, once connected, server returns:
220 whateverhostname.com FTP server ready.
The application the has to send a username, lets assume anonymous:
USER anonymous
The server will then return a code, lets say 331
331 Password required for admin
The application gets the code and determines what to do, default is to send the password, in most anonymous cases, an email address
PASS
me@there.com
The server then returns a code to say if the login is successful.
230 User anonymous logged in.
Now, the application needs to know what directory and host type we are dealing with, so that it knows what commands work, and which ones don't. So, it sends:
PWD
Which returns
257 "/" is current directory.
Now, host types rarely can be autodetected, but can be in the MOTD of the server, if it exists. Now, we have to know what ports to talk to eachother, so we have to send a port command with our IP in it, and the ports we wish to use. A note, for most FTP servers, we will have to do such a port command after every command that sends back data from the server. For this example, I won't include them, as it would only double the amount of typing I have to do to prove the point. Just double every command from here on in, and you'll get the idea.
PORT 55.33.22.11,12,249
The server will then return a code, in this case, let's assume it worked.
200 PORT command successful.
Now, we have to change to the right directory, so we do a:
CWD whateverdir
Server will return if it worked:
250 CWD command successful.
Lets confirm we're in the right directory now. Lets send:
PWD
Server will now return:
257 "/users" is current directory.
Okay, so now lets download the file. Your machine has to know if it's a binary or ascii file, but most applications will default to binary if it doesn't know what the file extension is. However, some will default to ascii. If the file is not transfered in the proper method, it will be horribly damaged, as every CR character will be converted to CRLF. We know it's binary, so I'll show that in the example. First we set the binary mode:
TYPE I
Server should respond:
200 Type set to I.
We now send a port command to ensure that the file gets sent to us.
PORT 55.33.22.11,13,36
Server should now respond:
200 PORT command successful.
Now we actually request the file:
RETR themp3.mp3
Server should respond:
150 Opening BINARY mode data connection for themp3.mp3 (size bytes).
And the data that follows should be the mp3.
We then wait for a :
226 Transfer complete.
And then log off of the server. (We could leave the connection open, but that is unethical, and very very few applications allow it)
QUIT
And wait for a:
221 Goodbye.
So, sure, you can say that HTTP has to send headers too, but it is WAY LESS OVERHEAD than FTP, and thus is inherently faster to download.
FTP is called 'File Transfer Protocol' sure, but was designed for SENDING, RECIEVING, and MANAGING files, and is robust for managing files on a multi-directory structure. HTTP is ONE WAY and designed specifically for SENDING data to a client, and thus is way more efficient at it.
W.