Transfer files from one system to another | Community
Skip to main content
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by kautuk_sahni

Hi 

It is a classics JAVA problem to transfer files across servers/instance/clients etc.

There are many posts/article available online to sole this:

Link:-http://www.java2s.com/Code/Java/Network-Protocol/TransferafileviaSocket.htm

// Transfer a file via Socket : Socket « Network Protocol « Java

 

Link:- http://mrbool.com/file-transfer-between-2-computers-with-java/24516

// File Transfer between 2 computers with Java

 

Link:- http://codereview.stackexchange.com/questions/27138/program-to-transfer-files-from-one-server-to-another-in-java-and-also-display-a

// Program to transfer files from one server to another in java and also display a progress bar on each file transfer

 

You can use "ServerSocket" for this.

Main logic is:

Socket socket = serverSocket.accept();
System.out.println("Accepted connection : " + socket);
File transferFile = new File ("Document.doc");
byte [] bytearray = new byte [(int)transferFile.length()];
FileInputStream fin = new FileInputStream(transferFile); 
BufferedInputStream bin = new BufferedInputStream(fin);
bin.read(bytearray,0,bytearray.length);
OutputStream os = socket.getOutputStream();
System.out.println("Sending Files...");
os.write(bytearray,0,bytearray.length);
os.flush(); socket.close();
System.out.println("File transfer complete");

 

I hope this would help you.

~kautuk

1 reply

kautuk_sahni
Community Manager
kautuk_sahniCommunity ManagerAccepted solution
Community Manager
December 23, 2016

Hi 

It is a classics JAVA problem to transfer files across servers/instance/clients etc.

There are many posts/article available online to sole this:

Link:-http://www.java2s.com/Code/Java/Network-Protocol/TransferafileviaSocket.htm

// Transfer a file via Socket : Socket « Network Protocol « Java

 

Link:- http://mrbool.com/file-transfer-between-2-computers-with-java/24516

// File Transfer between 2 computers with Java

 

Link:- http://codereview.stackexchange.com/questions/27138/program-to-transfer-files-from-one-server-to-another-in-java-and-also-display-a

// Program to transfer files from one server to another in java and also display a progress bar on each file transfer

 

You can use "ServerSocket" for this.

Main logic is:

Socket socket = serverSocket.accept();
System.out.println("Accepted connection : " + socket);
File transferFile = new File ("Document.doc");
byte [] bytearray = new byte [(int)transferFile.length()];
FileInputStream fin = new FileInputStream(transferFile); 
BufferedInputStream bin = new BufferedInputStream(fin);
bin.read(bytearray,0,bytearray.length);
OutputStream os = socket.getOutputStream();
System.out.println("Sending Files...");
os.write(bytearray,0,bytearray.length);
os.flush(); socket.close();
System.out.println("File transfer complete");

 

I hope this would help you.

~kautuk

Kautuk Sahni