Expand my Community achievements bar.

SOLVED

Transfer files from one system to another

Avatar

Level 1

Can anyone tell me about How to transfer files from one system to another in AEM by using Java code?

1 Accepted Solution

Avatar

Correct answer by
Administrator

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-ano...

// 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

View solution in original post

1 Reply

Avatar

Correct answer by
Administrator

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-ano...

// 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