File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Sockets and Internet Protocols and the fly likes Sending and handling files in a network Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Sending and handling files in a network" Watch "Sending and handling files in a network" New topic

Sending and handling files in a network

Mousa A. Rafi

Joined: Jan 30, 2005
Posts: 28
It might be helpful to read my topic: Keeping an image in database in the JDBC section to understand the main problem.

Well, what I want to do is, send a file (most likely jpg or gif) to another machine on the network and save it in a particular directory of that machine, with the file renamed to something else. For example, I have an image named mypic.jpg. My application will send this file to another machine and it will be saved there as /DBUser/images/user0001.jpg. So, what would be the neat and clean way to do this?

If I were to do this app using web technology, I would send the file using HTTP 'post' method and let the webserver and PHP do the rest on the remote / server machine. I have some experience of making simple client server applications with Java which simply talk to each other. But never worked with protocols. Will FTP be of any help?
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
FTP would be well suited because its whole purpose in life is transferring files. I'd probably try for that unless there is some reason an FTP server is not allowed on your network.

HTTP protocols would be some work to build multi-part requests. The Apache HTTP Client package would probably make that simpler. I haven't tried it first hand. It would also be some work to accept the uploaded file to the web server, again because of multi-part request structures. You can find open source or free solutions.

Raw sockets might be easier than HTTP. You have to hand build more of the parts, but you can make up your own very simple protocol.

Any of that sound useful?

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Mousa A. Rafi

Joined: Jan 30, 2005
Posts: 28
Stan James,
Thanks for your suggestions. They indeed sound useful to me. Well, as you mentioned, FTP is the most suitable solution and as long as it full-fills the constraints I mentioned earlier I'd really want to go for it. But, as you can guess, I wouldn't have started this topic if I knew how to do it in the first place.

What I would really wish for is a short program / example that works with FTP to get myself running and then go for the doc for details and advanced features.

Thanks once again for the help. By the way, I liked that quotation you used for signature.
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
You can run a standard ftp daemon on the server. For a client, Jakarta's Commons Net has a simple FTPClient I believe.
I agree. Here's the link:
subject: Sending and handling files in a network
jQuery in Action, 3rd edition