3

I want to transfer file from server linux to another server linux using java application. anyone give me a solution or example .

Vipin
  • 4,851
  • 3
  • 35
  • 65
beginerdeveloper
  • 785
  • 4
  • 17
  • 43

3 Answers3

1

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.

Vipin
  • 4,851
  • 3
  • 35
  • 65
0

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.
Community
  • 1
  • 1
Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
0

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.

SSH library for Java

Community
  • 1
  • 1
Manjunath D R
  • 371
  • 2
  • 8