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

0

2 Answers 2

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);
Sign up to request clarification or add additional context in comments.

3 Comments

is it not possible to achieve multiple SSH Connections through JSch?
It is possible. Simply repeat the snippet before for each SSH connection you need.
Multiple jumphost connection can be achieved through jsch setportforwarding method.
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".

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.