Package com.exasol.exasoltestsetup
Class SshConnection
- java.lang.Object
-
- com.exasol.exasoltestsetup.SshConnection
-
- All Implemented Interfaces:
AutoCloseable
public class SshConnection extends Object implements AutoCloseable
This class sets up a SSH port forwarding.
-
-
Constructor Summary
Constructors Constructor Description SshConnection(SessionBuilder sessionBuilder)Create a newSshConnection.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intaddForwardPortForwarding(int remotePort)Add a forward port forwarding.intaddForwardPortForwarding(int remotePort, String targetHost)Add a forward port forwarding.intaddReversePortForwarding(int localPort)Add a reverse port forwarding.voidclose()intfindFreePortOnServer()Find a free port on the server.SshExecutionrunCommand(String command)Run a shell command.SshExecutionrunCommandAsRoot(String command)Run a shell command as root.
-
-
-
Constructor Detail
-
SshConnection
public SshConnection(SessionBuilder sessionBuilder)
Create a newSshConnection.It automatically opens an SSH connection for forwarding.
- Parameters:
sessionBuilder- used to populate the parameters of the session
-
-
Method Detail
-
addReversePortForwarding
public int addReversePortForwarding(int localPort)
Add a reverse port forwarding.- Parameters:
localPort- local port to expose- Returns:
- port number on the server
-
addForwardPortForwarding
public int addForwardPortForwarding(int remotePort)
Add a forward port forwarding.- Parameters:
remotePort- port of the the server to connect to- Returns:
- local port
-
addForwardPortForwarding
public int addForwardPortForwarding(int remotePort, String targetHost)Add a forward port forwarding.- Parameters:
remotePort- port of the the server to connect totargetHost- the host to forward the request to- Returns:
- local port
-
runCommandAsRoot
public SshExecution runCommandAsRoot(String command)
Run a shell command as root.This is a synchronous method. It will block until the command is finished.
- Parameters:
command- command to run- Returns:
- command output (stdout)
-
runCommand
public SshExecution runCommand(String command)
Run a shell command.- Parameters:
command- command to run- Returns:
- ssh execution
-
findFreePortOnServer
public int findFreePortOnServer()
Find a free port on the server.- Returns:
- free port number
-
close
public void close()
- Specified by:
closein interfaceAutoCloseable
-
-