public interface SSHSession extends AutoCloseable
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Close this SSH session.
|
void |
copy(InputStream input,
String targetPath,
String targetName,
long size,
int permission,
Long lastAccessTime,
Long lastModifiedTime)
Copies content to remote host.
|
void |
copy(Path sourceFile,
String targetPath)
Copies a local file to the given target path
|
PortForwarding |
createLocalPortForward(String targetHost,
int targetPort,
int originatePort,
PortForwarding.DataConsumer dataConsumer)
Creates a local port forwarding channel from this SSH session.
|
SSHProcess |
execute(List<String> commands)
Executes a sequence of commands on the remote host.
|
default SSHProcess |
execute(String... commands)
Executes a sequence of commands on the remote host.
|
String |
executeAndWait(List<String> commands)
Executes a sequence of commands on the remote host and block until execution completed.
|
default String |
executeAndWait(String... commands)
Executes a sequence of commands on the remote host and block until execution completed.
|
InetSocketAddress |
getAddress()
Returns the remote host and port that this session is connected to.
|
String |
getUsername()
Returns the remote user name that this session used to connect to the remote host.
|
boolean |
isAlive()
Returns
true if the session is alive; otherwise return false. |
boolean isAlive()
true if the session is alive; otherwise return false.InetSocketAddress getAddress()
InetSocketAddress containing the target host and port of this sessionString getUsername()
default SSHProcess execute(String... commands) throws IOException
commands - the commands to executeIOException - if failed to execute command remotelySSHProcess execute(List<String> commands) throws IOException
commands - the commands to executeIOException - if failed to execute command remotelydefault String executeAndWait(String... commands) throws IOException
commands - the commands to executeIOException - if failed to execute command or command exit with non-zero values.String executeAndWait(List<String> commands) throws IOException
commands - the commands to executeIOException - if failed to execute command or command exit with non-zero values.void copy(Path sourceFile, String targetPath) throws IOException
sourceFile - source filetargetPath - the target path to copy toIOException - ifvoid copy(InputStream input, String targetPath, String targetName, long size, int permission, @Nullable Long lastAccessTime, @Nullable Long lastModifiedTime) throws IOException
input - InputStream for the source contenttargetPath - target path. If the path is an existing directory, file with the targetName will
be created under the given path. If the path doesn't exist or is an existing file,
content will be written/overwritten to the given pathtargetName - file name in the targetPath if targetPath is a directorysize - size of the contentpermission - permission of the target filelastAccessTime - the optional file last access time in milliseconds.
Both this and the lastModifiedTime should not be null to have time to be setlastModifiedTime - the optional file last modified time in milliseconds.
Both this and the lastAccessTime should not be null to have time to be setIOException - if failed to copy the contentPortForwarding createLocalPortForward(String targetHost, int targetPort, int originatePort, PortForwarding.DataConsumer dataConsumer) throws IOException
targetHost - the target hostname to forward totargetPort - the target port to forward tooriginatePort - the original port that the client is connect todataConsumer - A PortForwarding.DataConsumer for consuming incoming data from the forwarding channelPortForwarding for communicating with the forwarding channelIOException - if failed to open the port forwarding channelvoid close()
close in interface AutoCloseableCopyright © 2018 Cask Data, Inc. Licensed under the Apache License, Version 2.0.