File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Query on http and ftp Protocols Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Query on http and ftp Protocols" Watch "Query on http and ftp Protocols" New topic

Query on http and ftp Protocols

Rajpal Kandhari
Ranch Hand

Joined: Aug 26, 2000
Posts: 126
First, I am not sure I am posting this query in the right Forum´┐ŻModerators please check it out?
Yesterday someone asked me a very good question i.e. how to write code on you're web site that will invoke a File down load on the client Machine. It is same thing that we all very commonly used to down load free software packages on net.
I don't know how this thing works that's why I am posting this query here so that I can have expert opinion from Java Guru's.
Here I am writing what I know: Among all the protocols available to communicate between client machine and a server we are now using http protocol. It has the advantage that it is very effective for hypertext transfer as well as it can do file transfer. We need have to go separately for ftp protocols when we have to transfer small files or when we r transferring files in pieces. In ftp protocol all the file is send in one go from server to the client machine where as in http protocol same file is send in pieces. When downloading of one piece is completed then another piece (packet) is send from server.
This is what I think is the basic difference between the two protocols.
Other thing I want to clarify is: I am sending a request to a server, which has a listener, which listen only to http protocol. And send response back to client machine in http protocol. Can there be a situation that the listener at the server is listening only on http protocol and sending back request using ftp protocol? Because our browser is not protocol specific. It can communicate (send and receive) from the server using any protocol.
Please tell me if I make any sense? I know my knowledge is limited and there for I am looking for you Java Guru's for help, Please guide me.
Have a Nice Day,

Regards,<P>Raj.<BR>-------------------------<BR>Afforts should be Appriciated.<BR>-------------------------
Rajpal Kandhari
Ranch Hand

Joined: Aug 26, 2000
Posts: 126
Hello Friends,

After waiting for three days I am wonder that I have not made any sense In above talk.......
But still can any one Please take pain in going through what I have written and pls give me you're expert comments...
Carl Trusiak

Joined: Jun 13, 2000
Posts: 3340
Whew, sorry, this question winds up being broad enough to encompas a small book. But, I'll try and take a stab at it. From the server side, it's extremely difficult to envoke a send of anything to a client without them in some way initiating the communication. You can cause a file to be downloaded on a clients machine using several methods however. You can include a javascript which does a timed redirect to the file to be downloaded which will cause the browser (if javascript enabled) to download the file. You can send the file as a response to a request. One final thing you can do is to grab the clients URL and 'push' the file to their browser. However they are going to get the message to save or open and the ability to cancel the download.
FTP and HTTP actually work much the same in that the data is sent in packets between the client and the server. The size of these packets are determined by an agreement between the two and the network connection, the better the connection the bigger the packets. The main difference in the packets is the amount of header and trailer information each contain. HTTP includes a lot more data therefore it takes longer for information to be transferred.
The largest difference between the two protocols is the state of the connection. HTTP will only maintain the state for a singel request and response. For a server to recognize a client for a second request, 'session' information is needed. This information can be in the form of a cookie, information in the url request, information in the http header etc. FTP is a sessioned protocol once you connect and login, your connection is maintained between commands until it is closed bu either the client or the server.
Hope this sheads a little more light, Though it diffinatly isn't intended to be complete or exhaustive so....

I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
I agree. Here's the link:
subject: Query on http and ftp Protocols
It's not a secret anymore!