public class SSHAgent extends BaseAgent implements LocalizedClient, RemoteFileSystemManager, BandwidthControl
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
CIPHER
The cipher for the SSH connection.
|
static java.lang.String |
DEFAULT_SSH_PORT_STR |
static java.lang.String |
ENABLE_FILE_TRANSFER_ERROR_MESSAGE |
static java.lang.String |
FAIL_CONN_IF_NO_BUNNER |
static java.lang.String |
KBD_AUTH |
static java.lang.String |
KEY_AUTH |
static java.lang.String |
KEY_FILE
By default the SSH authentication method is by password.
|
static java.lang.String |
PASSPHRASE
Password for the SSH authentication.
|
static java.lang.String |
PASSWORD_AUTH |
static java.lang.String |
PORT
The SSH port.
|
static java.lang.String |
PROMPT_RESPONSES |
static java.lang.String |
PROMPTS
The prompts & responses for the keyboard interactive
|
static java.lang.String |
SESSION_TIMEOUT
This property is relevant when running session inside SSH session.
|
static java.lang.String |
SFTP_SUBSYSTEM_ERROR_MESSAGE |
static java.lang.String |
SSH_LOG_LEVEL
The external SSH library log level (one of the parameters.
|
static int |
SSH_VER1 |
static int |
SSH_VER2 |
static int |
SSH_VER2_1 |
static java.lang.String |
SSH_VERSION_1 |
static java.lang.String |
SSH_VERSION_2 |
static java.lang.String |
SSH_VERSION_2_OR_1 |
static java.lang.String |
VERSION
Which SSH version to connect.
|
static java.lang.String |
WAIT_FOR_DATA |
ANSI_ENCODING, ENCODING, OEM_ENCODING
Constructor and Description |
---|
SSHAgent(java.lang.String ipAddress,
java.lang.String userName,
java.lang.String password,
int connectTimeout,
int defaultCmdTimeout,
java.util.Properties properties) |
SSHAgent(java.lang.String ipAddress,
java.lang.String userName,
java.lang.String password,
int connectTimeout,
java.util.Properties properties) |
Modifier and Type | Method and Description |
---|---|
void |
alert(java.lang.String msg) |
boolean |
askConfirmation(java.lang.String message,
boolean defAnswer) |
void |
closed(SSHOutputStream out,
char[] buf,
int len)
This function is called from the SSHOutputStream through the Expector
interface when the stream is closed
|
void |
connect()
Trying to connect to the server through SSH protocol
|
void |
connected(SSHClient client) |
void |
disconnect()
Closing all the opened resources
|
void |
disconnected(SSHClient client,
boolean graceful) |
java.lang.String |
doExecuteCommand(java.lang.String command)
Invokes a command on the remote server.
|
java.lang.String |
doExecuteCommand(java.lang.String command,
boolean waitForTimeout) |
java.lang.String |
doExecuteCommand(java.lang.String command,
int cmdTimeout,
boolean waitForTimeout) |
DynamicParserTable |
doTableCommand(java.lang.String command)
Invokes a command on the remote server.
|
int |
downloadFile(java.lang.String localFilePath,
java.lang.String remoteFilePath,
boolean shouldOverrideLocalFile)
Download file from remote machine to probe using SCP protocol (SSH's
files transferring protocol).
|
int |
downloadFile(java.lang.String localFilePath,
java.lang.String remoteFilePath,
ExistingFileResolution localFileResolution)
Download the specified file (remoteFilePath) from remote machine to probe.
|
void |
executeSuCommand()
Start "SU" session (send "su -
|
void |
exitFromSu()
If we are in "SU" session ("su -
|
int[] |
getAuthTypes(SSHClientUser origin) |
int |
getBandwidthLimit()
Gets bandwidth limit for file operations in kilobits per second.
|
java.lang.String |
getChallengeResponse(SSHClientUser origin,
java.lang.String challenge) |
int |
getCipher(SSHClientUser origin) |
SSHRSAKeyFile |
getIdentityFile(SSHClientUser origin) |
java.lang.String |
getIdentityPassword(SSHClientUser origin) |
byte[] |
getLastCommandOutputBytes() |
java.lang.String |
getPassword(SSHClientUser origin) |
java.lang.String |
getShellCmdSeperator() |
java.lang.String |
getSsh2Error() |
java.lang.String |
getSudoCommands() |
java.lang.String |
getSudoPaths() |
java.lang.String |
getUsername(SSHClientUser origin) |
boolean |
isInSUMode() |
boolean |
isSuConfigured() |
boolean |
isVerbose() |
boolean |
licenseDialog(java.lang.String license) |
static void |
main(java.lang.String[] args) |
void |
open(SSHClient client) |
java.lang.String |
promptLine(java.lang.String prompt,
boolean echo)
Prompt for a single string.
|
java.lang.String |
promptLine(java.lang.String prompt,
java.lang.String defaultVal) |
int |
promptList(java.lang.String name,
java.lang.String instruction,
java.lang.String[] choices)
This function is only used by AppGate internal code so there is no need
to actually implement it in any other code.
|
java.lang.String[] |
promptMulti(java.lang.String[] prompts,
boolean[] echos)
Prompt for multiple strings.
|
java.lang.String[] |
promptMultiFull(java.lang.String name,
java.lang.String instruction,
java.lang.String[] prompts,
boolean[] echos)
Prompt for multiple strings.
|
java.lang.String |
promptPassword(java.lang.String prompt) |
void |
propsStateChanged(SSHPropertyHandler props) |
boolean |
quietPrompts() |
void |
reached(SSHOutputStream out,
char[] buf,
int len,
java.lang.String boundary)
This function is called from the SSHOutputStream through the Expector
interface
|
static java.lang.String |
removeMarkers(java.lang.String output)
Remove end/start markers from the specified output
|
void |
report(java.lang.String msg) |
void |
sessionStarted(SSHClient client) |
void |
setBandwidthLimit(int limit)
Sets bandwidth limit for file operations in kilobits per second.
|
void |
setCharset(java.nio.charset.Charset charset) |
void |
startNewSession(SSHClient client) |
java.lang.String |
toString() |
static java.lang.String |
translateBackspace(java.lang.String contents) |
int |
uploadFile(java.lang.String localFilePath,
java.lang.String remoteFilePath,
boolean shouldOverrideRemoteFile)
Upload file from probe to remote machine using SCP protocol (SSH files
transferring protocol).
|
int |
uploadFile(java.lang.String localFilePath,
java.lang.String remoteFilePath,
ExistingFileResolution remoteFileResolution)
Upload the specified file (localFilePath) from probe's machine to remote machine
|
boolean |
verifyKnownHosts(java.security.interfaces.RSAPublicKey hostPub) |
getCharsetName, getMaxCommandLength, parseTable, setMaxCommandLength, setProperty
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
getProperty
public static final java.lang.String PASSWORD_AUTH
public static final java.lang.String KEY_AUTH
public static final java.lang.String KBD_AUTH
public static final java.lang.String VERSION
public static final int SSH_VER1
public static final int SSH_VER2_1
public static final int SSH_VER2
public static final java.lang.String SSH_VERSION_1
public static final java.lang.String SSH_VERSION_2
public static final java.lang.String SSH_VERSION_2_OR_1
public static final java.lang.String PORT
public static final java.lang.String DEFAULT_SSH_PORT_STR
public static final java.lang.String SESSION_TIMEOUT
public static final java.lang.String SSH_LOG_LEVEL
public static final java.lang.String PASSPHRASE
public static final java.lang.String KEY_FILE
public static final java.lang.String CIPHER
public static final java.lang.String PROMPTS
public static final java.lang.String PROMPT_RESPONSES
public static final java.lang.String WAIT_FOR_DATA
public static final java.lang.String FAIL_CONN_IF_NO_BUNNER
public static final java.lang.String SFTP_SUBSYSTEM_ERROR_MESSAGE
public static final java.lang.String ENABLE_FILE_TRANSFER_ERROR_MESSAGE
public SSHAgent(java.lang.String ipAddress, java.lang.String userName, java.lang.String password, int connectTimeout, java.util.Properties properties) throws java.lang.Exception
java.lang.Exception
public SSHAgent(java.lang.String ipAddress, java.lang.String userName, java.lang.String password, int connectTimeout, int defaultCmdTimeout, java.util.Properties properties) throws java.lang.Exception
java.lang.Exception
public java.lang.String toString()
public java.lang.String getSudoCommands()
getSudoCommands
in class BaseAgent
public java.lang.String getSudoPaths()
getSudoPaths
in class BaseAgent
public java.lang.String getSsh2Error()
public static java.lang.String translateBackspace(java.lang.String contents)
public static java.lang.String removeMarkers(java.lang.String output)
output
- public void reached(SSHOutputStream out, char[] buf, int len, java.lang.String boundary)
out
- - the SSHOutputStreambuf
- - the bytes written to the streamlen
- - number of bytesboundary
- - the boundary string that was reachedpublic void closed(SSHOutputStream out, char[] buf, int len)
out
- - the SSHOutputStreambuf
- - the bytes written to the streamlen
- - num of bytespublic java.lang.String getShellCmdSeperator()
getShellCmdSeperator
in class BaseAgent
public DynamicParserTable doTableCommand(java.lang.String command) throws java.lang.Exception
BaseAgent
doTableCommand
in interface Agent
doTableCommand
in class BaseAgent
command
- the command to invokejava.lang.Exception
- when the command could not operate.public java.lang.String doExecuteCommand(java.lang.String command) throws java.lang.Exception
BaseAgent
doExecuteCommand
in interface Agent
doExecuteCommand
in class BaseAgent
command
- the command to invokejava.lang.Exception
- when the command could not operate.public java.lang.String doExecuteCommand(java.lang.String command, boolean waitForTimeout) throws java.lang.Exception
doExecuteCommand
in class BaseAgent
java.lang.Exception
public java.lang.String doExecuteCommand(java.lang.String command, int cmdTimeout, boolean waitForTimeout) throws java.lang.Exception
doExecuteCommand
in class BaseAgent
java.lang.Exception
public boolean isInSUMode()
public boolean isSuConfigured()
public void executeSuCommand() throws java.lang.Exception
java.lang.Exception
- - if we failed to start "SU" session.public void exitFromSu() throws java.lang.Exception
java.lang.Exception
- - if sending "exit" command failed from some reason.public void disconnect()
disconnect
in interface Agent
disconnect
in class BaseAgent
public void connect() throws java.lang.Exception
java.lang.Exception
public int uploadFile(java.lang.String localFilePath, java.lang.String remoteFilePath, boolean shouldOverrideRemoteFile) throws java.lang.Exception
uploadFile
in interface RemoteFileSystemManager
localFilePath
- - name of the file on probe to be uploaded to remote machine.remoteFilePath
- - name of the uploaded file on the remote machine (including
path)shouldOverrideRemoteFile
- - defines behavior in case remoteFilePath already exists.
Currently this flag is not supported (the method will always
overwrite remote file).java.lang.Exception
public int downloadFile(java.lang.String localFilePath, java.lang.String remoteFilePath, boolean shouldOverrideLocalFile) throws java.lang.Exception
downloadFile
in interface RemoteFileSystemManager
localFilePath
- - name of the downloaded file on probe (full absolute path).remoteFilePath
- - name of the file on remote machine to be downloaded (full
absolute path).shouldOverrideLocalFile
- - defines behaviour in case localFilePath contains a path to
file that already exists. If shouldOverrideLocalFile is set to
true, then local file will be overwritten with downloaded
file. Otherwise (shouldOverrideLocalFile=false), this method
won't do anything.java.lang.Exception
public int uploadFile(java.lang.String localFilePath, java.lang.String remoteFilePath, ExistingFileResolution remoteFileResolution) throws java.lang.Exception
uploadFile
in interface RemoteFileSystemManager
localFilePath
- - the path of the file to be upload from probe machineremoteFilePath
- - the path of the uploaded file on remote machineremoteFileResolution
- - defines behavior if the file on remote machine already exists.java.lang.Exception
- - exception is thrown in case the upload failed.public int downloadFile(java.lang.String localFilePath, java.lang.String remoteFilePath, ExistingFileResolution localFileResolution) throws java.lang.Exception
downloadFile
in interface RemoteFileSystemManager
localFilePath
- - defines the name of downloaded file on probe's machine.remoteFilePath
- - the path of the downloaded file on remote machine.localFileResolution
- - defines behavior if the localFilePath already exists on probe machine.java.lang.Exception
- - exception is thrown in case of download failed.public void startNewSession(SSHClient client)
public void sessionStarted(SSHClient client)
public void connected(SSHClient client)
public void open(SSHClient client)
public void disconnected(SSHClient client, boolean graceful)
public void report(java.lang.String msg)
public void alert(java.lang.String msg)
public void propsStateChanged(SSHPropertyHandler props)
public boolean askConfirmation(java.lang.String message, boolean defAnswer)
public boolean licenseDialog(java.lang.String license)
public boolean quietPrompts()
public java.lang.String promptLine(java.lang.String prompt, java.lang.String defaultVal) throws java.io.IOException
java.io.IOException
public java.lang.String promptPassword(java.lang.String prompt) throws java.io.IOException
java.io.IOException
public boolean isVerbose()
public java.lang.String getUsername(SSHClientUser origin) throws java.io.IOException
java.io.IOException
public java.lang.String getPassword(SSHClientUser origin) throws java.io.IOException
java.io.IOException
public java.lang.String getChallengeResponse(SSHClientUser origin, java.lang.String challenge) throws java.io.IOException
java.io.IOException
public int[] getAuthTypes(SSHClientUser origin)
public int getCipher(SSHClientUser origin)
public SSHRSAKeyFile getIdentityFile(SSHClientUser origin) throws java.io.IOException
java.io.IOException
public java.lang.String getIdentityPassword(SSHClientUser origin) throws java.io.IOException
java.io.IOException
public boolean verifyKnownHosts(java.security.interfaces.RSAPublicKey hostPub) throws java.io.IOException
java.io.IOException
public java.lang.String promptLine(java.lang.String prompt, boolean echo) throws SSH2UserCancelException
prompt
- The prompt string to showecho
- True if the text the user enters should be echoed.SSH2UserCancelException
public java.lang.String[] promptMulti(java.lang.String[] prompts, boolean[] echos) throws SSH2UserCancelException
prompts
- List of prompts to showechos
- List of boolean values which indicates if the text entered for
the corresponding prompt should be echoed.SSH2UserCancelException
public java.lang.String[] promptMultiFull(java.lang.String name, java.lang.String instruction, java.lang.String[] prompts, boolean[] echos) throws SSH2UserCancelException
name
- Suggested title of the dialoginstruction
- Instructions to show to user in the dialogprompts
- List of prompts to showechos
- List of boolean values which indicates if the text entered for
the corresponding prompt should be echoed.SSH2UserCancelException
public int promptList(java.lang.String name, java.lang.String instruction, java.lang.String[] choices) throws SSH2UserCancelException
It is used to let the user select one element in a list.
name
- Suggested title of dialoginstruction
- Instructions to show to userchoices
- Array of possible choicesSSH2UserCancelException
public byte[] getLastCommandOutputBytes() throws java.lang.Exception
getLastCommandOutputBytes
in interface LocalizedClient
java.lang.Exception
public void setCharset(java.nio.charset.Charset charset)
setCharset
in interface LocalizedClient
public int getBandwidthLimit()
getBandwidthLimit
in interface BandwidthControl
public void setBandwidthLimit(int limit)
setBandwidthLimit
in interface BandwidthControl
limit
- bandwidth limitpublic static void main(java.lang.String[] args)
Documentation Feedback
Copyright 2012 Micro Focus or one of its affiliates.