0

Currently we have 2 Unix servers A and B. To connect to B server, initially we used to first connect server A and then we will login to JumpHost B using SSH at the Unix prompt.

Now I am working on a simple tool in Java which has to download the files from server B.

In the sample code I got from the link below , if I pass the host details of B server, the host connection is failing.

When I pass the host details of A server the connection is success and able to download the files present in server A.

I need pointers on how to connect to server A and then server B through Java and download files from server B.

SSH Connection Java

Community
  • 1
  • 1
Nagendra Vummadi
  • 457
  • 1
  • 5
  • 12

2 Answers2

0

You can use the overthere library. First import the dependency:

<dependency>
    <groupId>com.xebialabs.overthere</groupId>
    <artifactId>overthere</artifactId>
    <version>4.4.2</version>
</dependency>

... and then connect to your severs (A, B, etc):

ConnectionOptions options = new ConnectionOptions();
options.set(ConnectionOptions.PASSWORD, passwd);
options.set(ConnectionOptions.CONNECTION_TIMEOUT_MILLIS, connectionTimeout);
options.set(ConnectionOptions.USERNAME, login);
options.set(ConnectionOptions.ADDRESS, host);
options.set(ConnectionOptions.OPERATING_SYSTEM, OperatingSystemFamily.UNIX);
options.set(SshConnectionBuilder.CONNECTION_TYPE, SshConnectionType.SCP);
OverthereConnection connection = Overthere.getConnection(SshConnectionBuilder.SSH_PROTOCOL, options);
Boni García
  • 4,618
  • 5
  • 28
  • 44
0

What you're actually looking for is what is called in Overthere a Jumpstation.

You want to connect like this: client -> Server A -> Server B

Using overthere you can setup that connection as follows:

ConnectionOptions jumpStationOptions = new ConnectionOptions();
jumpStationOptions.set(ConnectionOptions.ADDRESS, "Server A");
jumpStationOptions.set(ConnectionOptions.USERNAME, "Username A");
jumpStationOptions.set(ConnectionOptions.PASSWORD, "Password A");
jumpStationOptions.set(ConnectionOptions.PROTOCOL, "ssh-jumpstation");
jumpStationOptions.set(ConnectionOptions.OPERATING_SYSTEM, OperatingSystemFamily.UNIX);
ConnectionOptions options = new ConnectionOptions();
options.set(ConnectionOptions.PASSWORD, "Password B");
options.set(ConnectionOptions.USERNAME, "Username B");
options.set(ConnectionOptions.ADDRESS, "Server B");
options.set(ConnectionOptions.OPERATING_SYSTEM, OperatingSystemFamily.UNIX);
options.set(SshConnectionBuilder.CONNECTION_TYPE, SshConnectionType.SCP);
options.set(ConnectionOptions.JUMPSTATION, jumpStationOptions);
OverthereConnection connection = Overthere.getConnection(SshConnectionBuilder.SSH_PROTOCOL, options);

This setup will configure "Server A" to be used as a jumpstation to reach "Server B".

Hiery Nomus
  • 17,429
  • 2
  • 41
  • 37