I want to transfer file from server linux to another server linux using java application. anyone give me a solution or example .
-
2http://www.jcraft.com/jsch/examples/ – jmj Jul 12 '14 at 07:02
3 Answers
You can use Apache Commons Net API
Some sample programs are given at below links
http://commons.apache.org/proper/commons-net/examples/ftp/FTPClientExample.java http://www.journaldev.com/661/java-ftp-upload-example-using-apache-commons-net-api
This should be perfect solution for you, it is server to server file transfer example.

- 4,851
- 3
- 35
- 65
Given that both systems are Linux, I think that a simpler solution would be to use "scp".
All you need to do is set up some SSH keys, and then run this command from the Java application:
scp /path/to/source_file user_name@hostname:/path/to/dest_file
See this Question on how to run a Linux command from Java:
This has the following advantages:
- You can put the file anywhere on the remote system ... in one operation.
- You don't need to set up an FTP server on the remote system.
- The transfer can be done securely.
The only caveat with this approach is that you have to manage the SSH keys. In particular, you have to choose between:
- using a key pair with a pass-phrase which is more secure but requires some slightly tricky stuff to unlock the key (e.g. lookup "man ssh-agent"), or
- using a key pair without a pass-phrase which presents a security risk if your private key leaks.
Linux commands to transfer files from one system to another. These can be done in two ways.
From source system to destination system (Push mechanism)
scp scp /path/to/source_file user_name@hostname:/path/to/dest_file
From destination system to source system (Pull mechanism)
scp user_name@hostname:/path/to/dest_file /path/to/source_file
For doing this through java you can follow the below link.

- 1
- 1

- 371
- 2
- 8