File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Moving files from server A to server B using JSch Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Moving files from server A to server B using JSch" Watch "Moving files from server A to server B using JSch" New topic
Author

Moving files from server A to server B using JSch

Gopi Chand Maddula
Ranch Hand

Joined: May 11, 2010
Posts: 40

Hi JavaRanch,

I am trying to copy/move files from server A to server B. Both the servers are in Linux and it is done successfully. In order to do this my moving script files should be either on Server A or Server B.
But recently my requirement has been changed that my moving scripts should not be on both the servers i.e., the scripts for moving the files should be on server C, where the files will be moving within the servers A&B. So can any one help me achieving this scenario...

Thanks in Advance......
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19684
    
  20

I don't know JSch well and haven't been able to quickly find any Javadoc pages, so my answer's just going to be a guess.

I see two possible options:
1) copy the file from server A to server C, storing the contents in a temporary file. Then copy the file from server C to server B, after which you delete the temporary file.
2) do the same but without storing it as a file. If you can get an InputStream to the file on server A and an OutputStream to the file on server B, simply copy everything from the InputStream to the OutputStream. Data will still be going from server A through server C to server B, but there's no temporary file.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Anant Jagania
Ranch Hand

Joined: Oct 20, 2004
Posts: 49
Look at the SCP exampls at the following link. This would help you in achieving what you are looking for..

JSCH Examples
Gopi Chand Maddula
Ranch Hand

Joined: May 11, 2010
Posts: 40

Rob Spoor wrote:I don't know JSch well and haven't been able to quickly find any Javadoc pages, so my answer's just going to be a guess.

I see two possible options:
1) copy the file from server A to server C, storing the contents in a temporary file. Then copy the file from server C to server B, after which you delete the temporary file.
2) do the same but without storing it as a file. If you can get an InputStream to the file on server A and an OutputStream to the file on server B, simply copy everything from the InputStream to the OutputStream. Data will still be going from server A through server C to server B, but there's no temporary file.


Thanks for your suggestion Rob. I should give it a try.
But if the connection is lost in between the transfer of streams then it would be a big mess for me to get back that files as i am trying to move the files.

Look at the SCP exampls at the following link. This would help you in achieving what you are looking for..

JSCH Examples


I was just those examples only to move the files from server A to server B where my scripts would be on server A or Server B.
But in my case the moving scripts should be on Server C which is impossible to connect to two servers at a time using JSch.

If anybody had a solution for that please suggest me.
Anant Jagania
Ranch Hand

Joined: Oct 20, 2004
Posts: 49
Gopi Chand Maddula wrote: it is impossible to connect to two servers at a time using JSch.


I remember doing it earlier where I use to create two Session objects and provide two different servers information in two different session object. And executing commands on two server at a time in two different threads or same thread...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Moving files from server A to server B using JSch