Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Sockets and Internet Protocols and the fly likes Send a file across the network Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Send a file across the network" Watch "Send a file across the network" New topic
Author

Send a file across the network

dushantha Rathnayake
Ranch Hand

Joined: Feb 27, 2010
Posts: 103
Hi,

I have an client server application. in some cases I want to send files between server and client. But I don't know how to do it. Can I do it using socket programming? the files that I want to send can be documents, media files, text files, pdf files, ect.... . Actually I want to send a file across the network. please help me.

thank you.
Richard Golebiowski
Ranch Hand

Joined: May 05, 2010
Posts: 213

You could send it using FTP.
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
Sockets would work, and might be the fastest way to getting this implemented if the requirements are simple. Or you could use an embedded Java FTP server like http://mina.apache.org/ftpserver/ and a client like http://commons.apache.org/net/
dushantha Rathnayake
Ranch Hand

Joined: Feb 27, 2010
Posts: 103
Hi,

My application is not a web application. I need to implement this file sending on a LAN. If I can use socket programming to do this, then how can I do it? If you have an example code please post it or if you can give me a link please post them. I am new for this socket programming side. Please help me.

Thank you.
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
Searching for "java socket tutorial" should find the relevant chapter of the Sun Java Tutorial. It contains an example of a pair of standalone client/server applications that communicate via sockets.
Richard Golebiowski
Ranch Hand

Joined: May 05, 2010
Posts: 213

dushantha Rathnayake wrote:Hi,

My application is not a web application. I need to implement this file sending on a LAN. If I can use socket programming to do this, then how can I do it? If you have an example code please post it or if you can give me a link please post them. I am new for this socket programming side. Please help me.

Thank you.


It doesn't matter if it's a web application. As long as the network is TCP, you can use a FTP server and client as was suggested. For a project, I wrote a DOS FTP server in Java and a DOS client in Pascal that was used to replace file transfer vis modem in an application. The client was not a web application.
Andrey Kozhanov
Ranch Hand

Joined: Mar 12, 2010
Posts: 79
Hi!

Below is a very basic sample of using sockets for transfering files of any type over the network, but it could give you general idea. Output file is written to current server working directory and no additional checking is provided. So if file of the same name already exists, it would be overwritten.

Server.java


and Client.java
 
wood burning stoves
 
subject: Send a file across the network