Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Moving files from server A to server B using JSch

 
Gopi Chand Maddula
Ranch Hand
Posts: 41
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20550
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Anant Jagania
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 41
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic