public class SshjTool extends SshAbstractTool implements SshTool
Modifier and Type | Class and Description |
---|---|
static class |
SshjTool.Builder<T extends SshjTool,B extends SshjTool.Builder<T,B>> |
static class |
SshjTool.SshjToolBuilder |
SshAbstractTool.AbstractSshToolBuilder<T extends SshTool,B extends SshAbstractTool.AbstractSshToolBuilder<T,B>>, SshAbstractTool.SshAction<T>
BROOKLYN_CONFIG_KEY_PREFIX, PROP_ALLOCATE_PTY, PROP_CONNECT_TIMEOUT, PROP_HOST, PROP_LAST_ACCESS_DATE, PROP_LAST_MODIFICATION_DATE, PROP_OWNER_UID, PROP_PASSWORD, PROP_PERMISSIONS, PROP_PORT, PROP_PRIVATE_KEY_DATA, PROP_PRIVATE_KEY_FILE, PROP_PRIVATE_KEY_PASSPHRASE, PROP_SESSION_TIMEOUT, PROP_SSH_RETRY_DELAY, PROP_SSH_TRIES, PROP_SSH_TRIES_TIMEOUT, PROP_STRICT_HOST_KEY_CHECKING, PROP_TOOL_CLASS, PROP_USER
PROP_DIRECT_HEADER, PROP_ERR_STREAM, PROP_EXEC_ASYNC, PROP_EXEC_ASYNC_POLLING_TIMEOUT, PROP_EXEC_TIMEOUT, PROP_LOCAL_TEMP_DIR, PROP_NO_DELETE_SCRIPT, PROP_NO_EXTRA_OUTPUT, PROP_OUT_STREAM, PROP_RUN_AS_ROOT, PROP_SCRIPT_DIR, PROP_SCRIPT_HEADER, PROP_SEPARATOR, PROP_SUMMARY
Constructor and Description |
---|
SshjTool(java.util.Map<java.lang.String,?> map) |
Modifier and Type | Method and Description |
---|---|
static SshjTool.SshjToolBuilder |
builder() |
void |
connect() |
void |
connect(int maxAttempts)
Deprecated.
|
int |
copyFromServer(java.util.Map<java.lang.String,?> props,
java.lang.String pathAndFileOnRemoteServer,
java.io.File localFile)
Copies the file from the server at the given path.
|
int |
copyToServer(java.util.Map<java.lang.String,?> props,
byte[] contents,
java.lang.String pathAndFileOnRemoteServer) |
int |
copyToServer(java.util.Map<java.lang.String,?> props,
java.io.File localFile,
java.lang.String pathAndFileOnRemoteServer)
Copies the file to the server at the given path.
|
int |
copyToServer(java.util.Map<java.lang.String,?> props,
java.io.InputStream contents,
java.lang.String pathAndFileOnRemoteServer)
Closes the given input stream before returning.
|
void |
disconnect() |
int |
execCommands(java.util.Map<java.lang.String,?> props,
java.util.List<java.lang.String> commands,
java.util.Map<java.lang.String,?> env)
Executes the set of commands using ssh exec.
|
int |
execScript(java.util.Map<java.lang.String,?> props,
java.util.List<java.lang.String> commands,
java.util.Map<java.lang.String,?> env)
This creates a script containing the user's commands, copies it to the remote server, and
executes the script.
|
int |
execShellDirect(java.util.Map<java.lang.String,?> props,
java.util.List<java.lang.String> commands,
java.util.Map<java.lang.String,?> env) |
boolean |
isConnected() |
getHostAddress, getUsername, toString
execCommands, execScript, getOptionalVal
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
execCommands, execScript
public static SshjTool.SshjToolBuilder builder()
@Deprecated public void connect(int maxAttempts)
public void disconnect()
disconnect
in interface SshTool
public boolean isConnected()
isConnected
in interface SshTool
public int copyToServer(java.util.Map<java.lang.String,?> props, byte[] contents, java.lang.String pathAndFileOnRemoteServer)
copyToServer
in interface SshTool
SshTool.copyToServer(Map, File, String)
public int copyToServer(java.util.Map<java.lang.String,?> props, java.io.InputStream contents, java.lang.String pathAndFileOnRemoteServer)
SshTool
KnownSizeInputStream
for efficiency when the size of the stream is known.copyToServer
in interface SshTool
SshTool.copyToServer(Map, File, String)
public int copyToServer(java.util.Map<java.lang.String,?> props, java.io.File localFile, java.lang.String pathAndFileOnRemoteServer)
SshTool
The file will not preserve the permission of last _access_ date. Optional properties are:
SshTool.PROP_PERMISSIONS
SshTool.PROP_LAST_MODIFICATION_DATE
; not supported by all SshTool implementations
SshTool.PROP_LAST_ACCESS_DATE
; not supported by all SshTool implementations
copyToServer
in interface SshTool
public int copyFromServer(java.util.Map<java.lang.String,?> props, java.lang.String pathAndFileOnRemoteServer, java.io.File localFile)
SshTool
copyFromServer
in interface SshTool
public int execScript(java.util.Map<java.lang.String,?> props, java.util.List<java.lang.String> commands, java.util.Map<java.lang.String,?> env)
Executing commands directly is fraught with dangers! Here are other options, and their problems:
ShellTool.PROP_EXEC_ASYNC
to force this mode of execution.execScript
in interface ShellTool
execScript
in interface SshTool
#execScript(Map, List, Map)}
public int execShellDirect(java.util.Map<java.lang.String,?> props, java.util.List<java.lang.String> commands, java.util.Map<java.lang.String,?> env)
public int execCommands(java.util.Map<java.lang.String,?> props, java.util.List<java.lang.String> commands, java.util.Map<java.lang.String,?> env)
ShellTool
ShellTool.execScript(Map, List, Map)
),
but is not suitable if you need env values which are only set on a fully-fledged shell,
or if you want the entire block executed with root permission.
Common optional properties (which also apply to ShellTool.execScript(Map, List, Map)
) are:
ShellTool.PROP_OUT_STREAM
ShellTool.PROP_ERR_STREAM
ShellTool.PROP_SEPARATOR
(for some modes)
ShellTool.PROP_NO_EXTRA_OUTPUT
(often there is no extra output here)
ShellTool.PROP_RUN_AS_ROOT
is not typically supported here. Prefer ShellTool.execScript(Map, List, Map)
).execCommands
in interface ShellTool
execCommands
in interface SshTool
#execCommands(Map, List, Map)}