This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets 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.
Don't get me started about those stupid light bulbs.
subject: Sending and handling files in a network
Similar Threads
Applet Servlet Serialized Object
NX: Core distributed computing concept and locking
Keeping an image in database
Giving path alias to network folder in server.xml