SSHExec (Apache Ant API)
Description: declaration: package: org.apache.tools.ant.taskdefs.optional.ssh, class: SSHExec

# Class SSHExec

java.lang.Object
org.apache.tools.ant.ProjectComponent
org.apache.tools.ant.Task
org.apache.tools.ant.taskdefs.optional.ssh.SSHBase
org.apache.tools.ant.taskdefs.optional.ssh.SSHExec

All Implemented Interfaces:
  `Cloneable, LogListener`

public class SSHExec extends SSHBase
Executes a command on a remote machine via ssh.

Since:
  Ant 1.6 (created February 2, 2003)

- ## Field Summary

  ### Fields inherited from class Task

  `target, taskName, taskType, wrapper`
  Modifier and Type
  Field
  Description
  `protected Target`
  `target`
  Deprecated.
  since 1.6.x.
  `protected String`
  `taskName`
  Deprecated.
  since 1.6.x.
  `protected String`
  `taskType`
  Deprecated.
  since 1.6.x.
  `protected RuntimeConfigurable`
  `wrapper`
  Deprecated.
  since 1.6.x.

  ### Fields inherited from class ProjectComponent

  `description, location, project`
  Modifier and Type
  Field
  Description
  `protected String`
  `description`
  Deprecated.
  since 1.6.x.
  `protected Location`
  `location`
  Deprecated.
  since 1.6.x.
  `protected Project`
  `project`
  Deprecated.
  since 1.6.x.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `SSHExec()`
  Constructor for SSHExecTask.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `execute()`
  Execute the command on the remote host.
  `void`
  `setAppend(boolean append)`
  Determines if the output is appended to the file given in `setOutput`.
  `void`
  `setBindSensitive(String bindSensitive)`
  Sets the placeholders with sensitive data to replace in command, Prevents from sensitive data appearance in logs
  `void`
  `setCommand(String command)`
  Sets the command to execute on the remote host.
  `void`
  `setCommandResource(String f)`
  Sets a commandResource from a file
  `void`
  `setErrAppend(boolean appenderr)`
  Determines if the output is appended to the file given in `setErrorOutput`.
  `void`
  `setErrorOutput(File output)`
  If used, stores the erroutput of the command to the given file.
  `void`
  `setErrorproperty(String property)`
  If set, the erroroutput of the command will be stored in the given property.
  `void`
  `setHideSensitive(boolean hideSensitive)`
  If hideSensitive is `true`, command will be checked for placeholders to replace, If hideSensitive is `false`, command will be executed as is, Prevents from sensitive data appearance in logs
  `void`
  `setInput(File input)`
  If used, the content of the file is piped to the remote command
  `void`
  `setInputProperty(String inputProperty)`
  If used, the content of the property is piped to the remote command
  `void`
  `setInputString(String inputString)`
  If used, the string is piped to the remote command.
  `void`
  `setOutput(File output)`
  If used, stores the output of the command to the given file.
  `void`
  `setOutputproperty(String property)`
  If set, the output of the command will be stored in the given property.
  `void`
  `setPlaceholderBrackets(String placeholderBrackets)`
  Sets delimiter to find placeholders and replace them
  `void`
  `setResultproperty(String property)`
  If set, the exitcode of the command will be stored in the given property.
  `void`
  `setSensitiveDelimiter(String sensitiveDelimiter)`
  Sets the delimiter of sensitive data key values pairs in bindSensitive
  `void`
  `setSuppressSystemErr(boolean suppressSystemErr)`
  If suppressSystemErr is `true`, output will not be sent to System.err, if suppressSystemErr is `false`, normal behavior
  `void`
  `setSuppressSystemOut(boolean suppressSystemOut)`
  If suppressSystemOut is `true`, output will not be sent to System.out, if suppressSystemOut is `false`, normal behavior
  `void`
  `setTimeout(long timeout)`
  The connection can be dropped after a specified number of milliseconds.
  `void`
  `setUsePty(boolean b)`
  Whether a pseudo-tty should be allocated.
  `void`
  `setUseSystemIn(boolean useSystemIn)`
  If set, input will be taken from System.in

  ### Methods inherited from class SSHBase

  `addConfiguredAdditionalConfig, getFailonerror, getHost, getPort, getServerAliveCountMax, getServerAliveIntervalSeconds, getSshConfig, getUserInfo, getVerbose, init, loadSshConfig, openSession, setFailonerror, setHost, setKeyfile, setKnownhosts, setPassphrase, setPassword, setPort, setServerAliveCountMax, setServerAliveIntervalSeconds, setSshConfig, setTrust, setUsername, setVerbose`
  Modifier and Type
  Method
  Description
  `void`
  `addConfiguredAdditionalConfig(Environment.Variable v)`
  `boolean`
  `getFailonerror()`
  Get the failonerror flag.
  `String`
  `getHost()`
  Get the host.
  `int`
  `getPort()`
  Get the port attribute.
  `int`
  `getServerAliveCountMax()`
  Get the serverAliveCountMax value.
  `int`
  `getServerAliveIntervalSeconds()`
  Get the serverAliveIntervalSeconds value in seconds.
  `String`
  `getSshConfig()`
  Get the OpenSSH config file (~/.ssh/config).
  `protected SSHUserInfo`
  `getUserInfo()`
  Get the user information.
  `boolean`
  `getVerbose()`
  Get the verbose flag.
  `void`
  `init()`
  Initialize the task.
  `protected void`
  `loadSshConfig()`
  Load the SSH configuration file.
  `protected com.jcraft.jsch.Session`
  `openSession()`
  Open an ssh session.
  `void`
  `setFailonerror(boolean failure)`
  Set the failonerror flag.
  `void`
  `setHost(String host)`
  Remote host, either DNS name or IP.
  `void`
  `setKeyfile(String keyfile)`
  Sets the keyfile for the user.
  `void`
  `setKnownhosts(String knownHosts)`
  Sets the path to the file that has the identities of all known hosts.
  `void`
  `setPassphrase(String passphrase)`
  Sets the passphrase for the users key.
  `void`
  `setPassword(String password)`
  Sets the password for the user.
  `void`
  `setPort(int port)`
  Changes the port used to connect to the remote host.
  `void`
  `setServerAliveCountMax(int countMax)`
  Set the serverAliveCountMax value.
  `void`
  `setServerAliveIntervalSeconds(int interval)`
  Set the serverAliveIntervalSeconds value in seconds.
  `void`
  `setSshConfig(String sshConfig)`
  Set the OpenSSH config file (~/.ssh/config).
  `void`
  `setTrust(boolean yesOrNo)`
  Setting this to true trusts hosts whose identity is unknown.
  `void`
  `setUsername(String username)`
  Username known to remote host.
  `void`
  `setVerbose(boolean verbose)`
  Set the verbose flag.

  ### Methods inherited from class Task

  `bindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType`
  Modifier and Type
  Method
  Description
  `final void`
  `bindToOwner(Task owner)`
  Bind a task to another; use this when configuring a newly created task to do work on behalf of another.
  `Target`
  `getOwningTarget()`
  Returns the container target of this task.
  `RuntimeConfigurable`
  `getRuntimeConfigurableWrapper()`
  Returns the wrapper used for runtime configuration.
  `String`
  `getTaskName()`
  Returns the name to use in logging messages.
  `String`
  `getTaskType()`
  Return the type of task.
  `protected RuntimeConfigurable`
  `getWrapper()`
  Return the runtime configurable structure for this task.
  `protected void`
  `handleErrorFlush(String output)`
  Handles an error line by logging it with the WARN priority.
  `protected void`
  `handleErrorOutput(String output)`
  Handles an error output by logging it with the WARN priority.
  `protected void`
  `handleFlush(String output)`
  Handles output by logging it with the INFO priority.
  `protected int`
  `handleInput(byte[] buffer, int offset, int length)`
  Handle an input request by this task.
  `protected void`
  `handleOutput(String output)`
  Handles output by logging it with the INFO priority.
  `protected final boolean`
  `isInvalid()`
  Has this task been marked invalid?
  `void`
  `log(String msg)`
  Logs a message with the default (INFO) priority.
  `void`
  `log(String msg, int msgLevel)`
  Logs a message with the given priority.
  `void`
  `log(String msg, Throwable t, int msgLevel)`
  Logs a message with the given priority.
  `void`
  `log(Throwable t, int msgLevel)`
  Logs a message with the given priority.
  `void`
  `maybeConfigure()`
  Configures this task - if it hasn't been done already.
  `final void`
  `perform()`
  Performs this task if it's still valid, or gets a replacement version and performs that otherwise.
  `void`
  `reconfigure()`
  Force the task to be reconfigured from its RuntimeConfigurable.
  `void`
  `setOwningTarget(Target target)`
  Sets the target container of this task.
  `void`
  `setRuntimeConfigurableWrapper(RuntimeConfigurable wrapper)`
  Sets the wrapper to be used for runtime configuration.
  `void`
  `setTaskName(String name)`
  Sets the name to use in logging messages.
  `void`
  `setTaskType(String type)`
  Sets the name with which the task has been invoked.

  ### Methods inherited from class ProjectComponent

  `clone, getDescription, getLocation, getProject, setDescription, setLocation, setProject`
  Modifier and Type
  Method
  Description
  `Object`
  `clone()`
  `String`
  `getDescription()`
  Returns the description of the current action.
  `Location`
  `getLocation()`
  Returns the file/location where this task was defined.
  `Project`
  `getProject()`
  Returns the project to which this component belongs.
  `void`
  `setDescription(String desc)`
  Sets a description of the current action.
  `void`
  `setLocation(Location location)`
  Sets the file/location where this task was defined.
  `void`
  `setProject(Project project)`
  Sets the project object of this component.

  ### Methods inherited from class Object

  `equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

  ### Methods inherited from interface LogListener

  `log`
  Modifier and Type
  Method
  Description
  `void`
  `log(String message)`
  Method for the loglistener to implement to receive log messages.

- ## Constructor Details

  - ### SSHExec

    public SSHExec()
    Constructor for SSHExecTask.

- ## Method Details

  - ### setCommand

    public void setCommand(String command)
    Sets the command to execute on the remote host.
    Parameters:
      `command` - The new command value

  - ### setCommandResource

    public void setCommandResource(String f)
    Sets a commandResource from a file
    Parameters:
      `f` - the value to use.
    Since:
      Ant 1.7.1

  - ### setTimeout

    public void setTimeout(long timeout)
    The connection can be dropped after a specified number of milliseconds. This is sometimes useful when a connection may be flaky. Default is 0, which means "wait forever".
    Parameters:
      `timeout` - The new timeout value in seconds

  - ### setOutput

    public void setOutput(File output)
    If used, stores the output of the command to the given file.
    Parameters:
      `output` - The file to write to.

  - ### setErrorOutput

    public void setErrorOutput(File output)
    If used, stores the erroutput of the command to the given file.
    Parameters:
      `output` - The file to write to.
    Since:
      Apache Ant 1.9.4

  - ### setInput

    public void setInput(File input)
    If used, the content of the file is piped to the remote command
    Parameters:
      `input` - The file which provides the input data for the remote command
    Since:
      Ant 1.8.0

  - ### setInputProperty

    public void setInputProperty(String inputProperty)
    If used, the content of the property is piped to the remote command
    Parameters:
      `inputProperty` - The property which contains the input data for the remote command.
    Since:
      Ant 1.8.0

  - ### setInputString

    public void setInputString(String inputString)
    If used, the string is piped to the remote command.
    Parameters:
      `inputString` - the input data for the remote command.
    Since:
      Ant 1.8.3

  - ### setAppend

    public void setAppend(boolean append)
    Determines if the output is appended to the file given in `setOutput`. Default is false, that is, overwrite the file.
    Parameters:
      `append` - True to append to an existing file, false to overwrite.

  - ### setErrAppend

    public void setErrAppend(boolean appenderr)
    Determines if the output is appended to the file given in `setErrorOutput`. Default is false, that is, overwrite the file.
    Parameters:
      `appenderr` - True to append to an existing file, false to overwrite.
    Since:
      Apache Ant 1.9.4

  - ### setOutputproperty

    public void setOutputproperty(String property)
    If set, the output of the command will be stored in the given property.
    Parameters:
      `property` - The name of the property in which the command output will be stored.

  - ### setErrorproperty

    public void setErrorproperty(String property)
    If set, the erroroutput of the command will be stored in the given property.
    Parameters:
      `property` - The name of the property in which the command erroroutput will be stored.
    Since:
      Apache Ant 1.9.4

  - ### setResultproperty

    public void setResultproperty(String property)
    If set, the exitcode of the command will be stored in the given property.
    Parameters:
      `property` - The name of the property in which the exitcode will be stored.
    Since:
      Apache Ant 1.9.4

  - ### setUsePty

    public void setUsePty(boolean b)
    Whether a pseudo-tty should be allocated.
    Parameters:
      `b` - boolean
    Since:
      Apache Ant 1.8.3

  - ### setUseSystemIn

    public void setUseSystemIn(boolean useSystemIn)
    If set, input will be taken from System.in
    Parameters:
      `useSystemIn` - True to use System.in as InputStream, false otherwise
    Since:
      Apache Ant 1.9.4

  - ### setSuppressSystemOut

    public void setSuppressSystemOut(boolean suppressSystemOut)
    If suppressSystemOut is `true`, output will not be sent to System.out, if suppressSystemOut is `false`, normal behavior
    Parameters:
      `suppressSystemOut` - boolean
    Since:
      Ant 1.9.0

  - ### setSuppressSystemErr

    public void setSuppressSystemErr(boolean suppressSystemErr)
    If suppressSystemErr is `true`, output will not be sent to System.err, if suppressSystemErr is `false`, normal behavior
    Parameters:
      `suppressSystemErr` - boolean
    Since:
      Ant 1.9.4

  - ### setHideSensitive

    public void setHideSensitive(boolean hideSensitive)
    If hideSensitive is `true`, command will be checked for placeholders to replace, If hideSensitive is `false`, command will be executed as is, Prevents from sensitive data appearance in logs
    Parameters:
      `hideSensitive` - boolean

  - ### setBindSensitive

    public void setBindSensitive(String bindSensitive)
    Sets the placeholders with sensitive data to replace in command, Prevents from sensitive data appearance in logs
    Parameters:
      `bindSensitive` - String

  - ### setSensitiveDelimiter

    public void setSensitiveDelimiter(String sensitiveDelimiter)
    Sets the delimiter of sensitive data key values pairs in bindSensitive
    Parameters:
      `sensitiveDelimiter` - String

  - ### setPlaceholderBrackets

    public void setPlaceholderBrackets(String placeholderBrackets)
    Sets delimiter to find placeholders and replace them
    Parameters:
      `placeholderBrackets` - String

  - ### execute

    public void execute() throws BuildException
    Execute the command on the remote host.
    Overrides:
      `execute` in class `Task`
    Throws:
      `BuildException` - Most likely a network error or bad parameter.