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

# Class SSHSession

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.SSHSession

All Implemented Interfaces:
  `Cloneable, LogListener`

public class SSHSession extends SSHBase
Establishes an ssh session with a remote machine, optionally establishing port forwarding, then executes any nested task(s) before closing the session.

Since:
  Ant 1.8.0

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `class`
  `SSHSession.LocalTunnel`
  `static class`
  `SSHSession.NestedSequential`
  The class corresponding to the sequential nested element.
  `class`
  `SSHSession.RemoteTunnel`

- ## 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
  `SSHSession()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `addTask(Task nestedTask)`
  Add a nested task to Sequential.
  `SSHSession.LocalTunnel`
  `createLocalTunnel()`
  `SSHSession.RemoteTunnel`
  `createRemoteTunnel()`
  `SSHSession.NestedSequential`
  `createSequential()`
  This is the sequential nested element of the macrodef.
  `void`
  `execute()`
  Establish the ssh session and execute all nestedTasks
  `void`
  `setLocaltunnels(String tunnels)`
  Changes the comma-delimited list of local tunnels to establish on the connection.
  `void`
  `setRemotetunnels(String tunnels)`
  Changes the comma-delimited list of remote tunnels to establish on the connection.
  `void`
  `setTimeout(long timeout)`
  The connection can be dropped after a specified number of milliseconds.

  ### 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

  - ### SSHSession

    public SSHSession()

- ## Method Details

  - ### addTask

    public void addTask(Task nestedTask)
    Add a nested task to Sequential.
    Parameters:
      `nestedTask` - Nested task to execute sequentially

  - ### 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

  - ### setLocaltunnels

    public void setLocaltunnels(String tunnels)
    Changes the comma-delimited list of local tunnels to establish on the connection.
    Parameters:
      `tunnels` - a comma-delimited list of lport:rhost:rport tunnel specifications

  - ### setRemotetunnels

    public void setRemotetunnels(String tunnels)
    Changes the comma-delimited list of remote tunnels to establish on the connection.
    Parameters:
      `tunnels` - a comma-delimited list of rport:lhost:lport tunnel specifications

  - ### execute

    public void execute() throws BuildException
    Establish the ssh session and execute all nestedTasks
    Overrides:
      `execute` in class `Task`
    Throws:
      `BuildException` - if one of the nested tasks fails, or network error or bad parameter.

  - ### createLocalTunnel

    public SSHSession.LocalTunnel createLocalTunnel()

  - ### createRemoteTunnel

    public SSHSession.RemoteTunnel createRemoteTunnel()

  - ### createSequential

    public SSHSession.NestedSequential createSequential()
    This is the sequential nested element of the macrodef.
    Returns:
      a sequential element to be configured.