public abstract class ShellClient extends BaseClient implements LocalizedClient, RemoteFileSystemManager, RemoteAgentOptionsManager, BandwidthControl
ShellClient
runs shell commands.
Thd principle methods are executeCmd(java.lang.String)
and executeCmdWithTimeOut(java.lang.String)
.
The output of these methods is the console output of shell this client represents.
# Example: Creating a telnet client
client = Framework.getClientFactory(ClientsConsts.TELNET_PROTOCOL_NAME).createClient()
output = client.executeCmd('df -P')
ClientsConsts
,
ClientFactory
BaseClient.FilteredMethodsHandler
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
UNIX_CMD_SEPARATOR |
static java.lang.String |
WIN_CMD_SEPARATOR |
CREDENTIALS_ID, ENCODING
Constructor and Description |
---|
ShellClient(ClientsFrameworkImpl framework,
java.util.Properties props,
java.lang.String clientType) |
Modifier and Type | Method and Description |
---|---|
boolean |
canCopyFile()
// @return true if the client can copy files to the remote machine
//* begin no Javadoc
|
boolean |
deleteFile(java.lang.String remoteFileName,
java.lang.String remoteShareName) |
boolean |
deleteOption(java.lang.String key)
Deletes the remote setting on a remote machine by a given key
|
int |
downloadFile(java.lang.String localFilePath,
java.lang.String remoteFilePath,
boolean shouldOverrideLocalFile)
Download the specified file (remoteFilePath) from remote machine to probe.
|
java.lang.String |
executeCmd(java.lang.String cmd)
Runs the specified command.
|
java.lang.String |
executeCmd(java.lang.String cmd,
boolean readUntilTimeout)
Runs the specified command until completion or timeout.
|
java.lang.String |
executeCmd(java.lang.String cmd,
int cmdTimeout)
Runs the specified command until completion or the specified timeout.
|
java.lang.String |
executeCmd(java.lang.String cmd,
int cmdTimeout,
boolean readUntilTimeout)
Runs the specified command until completion or the specified timeout.
|
java.lang.String |
executeCmd(java.lang.String cmd,
int cmdTimeout,
boolean readUntilTimeout,
Runs the specified command until completion or the specified timeout.
|
java.lang.String |
executeCmdWithTimeOut(java.lang.String cmd)
Runs the specified command until completion or timeout.
|
int |
getBandwidthLimit()
Gets bandwidth limit for file operations in kilobits per second.
|
java.lang.String |
getErrorVariable() |
java.lang.String |
getFile(java.lang.String remoteFileName,
java.lang.String remoteShareName) |
byte[] |
getLastCommandOutputBytes() |
int |
getMaxCommandLength()
Returns the maximum length (bytes) of a command that can be sent to this client.
|
java.lang.String |
getOptionsDirectory()
Getting directory for remote settings
|
java.util.Map<java.lang.String,java.lang.String> |
getOptionsMap()
Get all remote agent settings
|
java.lang.String |
getRemotePlatform() |
java.lang.String |
getServerPort()
Returns the server port from the protocol properties.
|
java.lang.String |
getWelcomeBuffer() |
java.lang.String |
putFile(java.lang.String localFileName,
java.lang.String remoteShareName) |
void |
setBandwidthLimit(int limit)
Sets bandwidth limit for file operations in kilobits per second.
|
void |
setCharset(java.nio.charset.Charset charset) |
void |
setErrorVariable(java.lang.String errorVariable) |
void |
setMaxCommandLength(int maxCommandLength)
Sets the maximum length (bytes) of a command that can be sent to this client.
|
java.lang.String |
setOptionIfNotExist(java.lang.String key,
java.lang.String value)
Attempts to set a value to the given key on a remote machine, if such key doesn't already exist
|
void |
setOptionsDirectory(java.lang.String optionsDirectory)
/** Setting directory for remote settings
|
void |
setOptionsMap(java.util.Map<java.lang.String,java.lang.String> settingsMap)
Sets remote agent setting
|
void |
setOptionsMap(java.util.Map<java.lang.String,java.lang.String> settingsMap,
boolean cleanExistingValues)
Sets remote agent's settings.
|
void |
setRemotePlatform(java.lang.String platformId) |
int |
uploadFile(java.lang.String localFilePath,
java.lang.String remoteFilePath,
boolean shouldOverrideRemoteFile)
Upload the specified file (localFilePath) from probe's machine to remote machine
|
addDeniedPackage, close, getClientType, getCredentialId, getIpAddress, getProperty, getShellCmdSeperator, getSudoCommands, getSudoPaths, getTimeout, getUserName, isConnected, setAttributeEncrypted, supportsSudo
public static final java.lang.String UNIX_CMD_SEPARATOR
public static final java.lang.String WIN_CMD_SEPARATOR
public ShellClient(ClientsFrameworkImpl framework, java.util.Properties props, java.lang.String clientType) throws java.lang.Exception
java.lang.Exception
public java.lang.String getWelcomeBuffer()
public java.lang.String getRemotePlatform()
public void setRemotePlatform(java.lang.String platformId)
public void setErrorVariable(java.lang.String errorVariable)
public java.lang.String getErrorVariable()
public java.lang.String executeCmdWithTimeOut(java.lang.String cmd) throws java.lang.Exception
cmd
- The command to runjava.lang.Exception
- on connection errorpublic java.lang.String executeCmd(java.lang.String cmd) throws java.lang.Exception
cmd
- The command to runjava.lang.Exception
- on connection error or timeoutpublic java.lang.String executeCmd(java.lang.String cmd, boolean readUntilTimeout) throws java.lang.Exception
cmd
- The command to runreadUntilTimeout
- The effect of this parameter is implementation dependent
java.lang.Exception
public java.lang.String executeCmd(java.lang.String cmd, int cmdTimeout) throws java.lang.Exception
cmd
- The command to runcmdTimeout
- The timeout in millisecondsjava.lang.Exception
public java.lang.String executeCmd(java.lang.String cmd, int cmdTimeout, boolean readUntilTimeout) throws java.lang.Exception
cmd
- The command to runcmdTimeout
- The timeout in millisecondsreadUntilTimeout
- If true, the command fails if the default timeout is reached.
If false, the command runs to completion or until it throws a fatal error.java.lang.Exception
public java.lang.String executeCmd(java.lang.String cmd, int cmdTimeout, boolean readUntilTimeout,agentExecutor) throws java.lang.Exception
cmd
- The command to runcmdTimeout
- The timeout in millisecondsreadUntilTimeout
- If true, the command fails if the default timeout is reached.
If false, the command runs to completion or until it throws a fatal error.agentExecutor
- object to help execute command using agentjava.lang.Exception
public byte[] getLastCommandOutputBytes() throws java.lang.Exception
getLastCommandOutputBytes
in interface LocalizedClient
java.lang.Exception
public void setCharset(java.nio.charset.Charset charset) throws java.lang.Exception
setCharset
in interface LocalizedClient
java.lang.Exception
public int getBandwidthLimit()
BandwidthControl
getBandwidthLimit
in interface BandwidthControl
public void setBandwidthLimit(int limit)
BandwidthControl
setBandwidthLimit
in interface BandwidthControl
limit
- bandwidth limitpublic java.lang.String getServerPort() throws java.lang.Exception
java.lang.Exception
public void setOptionsDirectory(java.lang.String optionsDirectory)
setOptionsDirectory
in interface RemoteAgentOptionsManager
optionsDirectory
- optionsDirectory directory for remote settingspublic java.lang.String getOptionsDirectory()
getOptionsDirectory
in interface RemoteAgentOptionsManager
public int uploadFile(java.lang.String localFilePath, java.lang.String remoteFilePath, boolean shouldOverrideRemoteFile) throws java.lang.Exception
RemoteFileSystemManager
uploadFile
in interface RemoteFileSystemManager
localFilePath
- - the path of the file to be upload from probe machineremoteFilePath
- - the path of the uploaded file on remote machineshouldOverrideRemoteFile
- - what to do if the file on remote machine already exists.
True will cause to override the file on remote machine, false will cause to not to upload the file if it already
exists.java.lang.Exception
- - exception is thrown in case the upload failed.public int downloadFile(java.lang.String localFilePath, java.lang.String remoteFilePath, boolean shouldOverrideLocalFile) throws java.lang.Exception
RemoteFileSystemManager
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.shouldOverrideLocalFile
- - defines behavior if the localFilePath already exists on probe machine.
True to override already existing local file with the downloaded file. False to not to perform download if the
localFilePath already exists.java.lang.Exception
- - exception is thrown in case of download failed.public boolean canCopyFile()
public java.lang.String getFile(java.lang.String remoteFileName, java.lang.String remoteShareName) throws java.lang.Exception
remoteFileName
- -
file name we want to get from remote machineremoteShareName
- -
name of the remote share from which we want to get the filejava.lang.Exception
public java.lang.String putFile(java.lang.String localFileName, java.lang.String remoteShareName) throws java.lang.Exception
java.lang.Exception
public boolean deleteFile(java.lang.String remoteFileName, java.lang.String remoteShareName) throws java.lang.Exception
java.lang.Exception
public java.util.Map<java.lang.String,java.lang.String> getOptionsMap() throws java.lang.Exception
getOptionsMap
in interface RemoteAgentOptionsManager
java.lang.Exception
- if failed to get remote agent's settingspublic void setOptionsMap(java.util.Map<java.lang.String,java.lang.String> settingsMap) throws java.lang.Exception
setOptionsMap
in interface RemoteAgentOptionsManager
settingsMap
- - map that contains pairs of options (option name and option value) to be set on remote machinejava.lang.Exception
- if failed to set remote agent's settingspublic void setOptionsMap(java.util.Map<java.lang.String,java.lang.String> settingsMap, boolean cleanExistingValues) throws java.lang.Exception
setOptionsMap
in interface RemoteAgentOptionsManager
settingsMap
- - map that contains pairs of options (option name and option value) to be set on remote machinecleanExistingValues
- - if set to true, then this operation clears all remote agent's options except of the
options that are passed in settingsMapjava.lang.Exception
- if failed to set remote agent's settingspublic java.lang.String setOptionIfNotExist(java.lang.String key, java.lang.String value) throws java.lang.Exception
setOptionIfNotExist
in interface RemoteAgentOptionsManager
key
- keyvalue
- valuejava.lang.Exception
- if something bad happenspublic boolean deleteOption(java.lang.String key)
deleteOption
in interface RemoteAgentOptionsManager
key
- key to removepublic int getMaxCommandLength() throws java.lang.Exception
java.lang.Exception
public void setMaxCommandLength(int maxCommandLength) throws java.lang.Exception
java.lang.Exception
Documentation Feedback
Copyright 2012 Micro Focus or one of its affiliates.