com.jscape.inet.ssh

## Class SshTask

- java.lang.Object
- - com.jscape.inet.ssh.SshTask

- All Implemented Interfaces:
    java.io.Serializable

      public class SshTask
      extends java.lang.Object
      implements java.io.Serializable

  The SshTask class represents a command to be executed in batch (non-interactive) mode on SSH server. In order to execute a command in batch mode the SshTask must know the following:

  Start Prompt - The start prompt is the data that is sent back by the SSH server indicating that it is ready to execute the command. e.g. $

  Message - The command is the command to be executed. e.g. ls -al

  End Prompt - The end prompt is the data that is sent back by the SSH server indicating that it has completed execution of the command. In most cases this is the same as the Start Prompt. e.g. $

  When creating a new SshTask you must at a MINIMUM provide both the Message and End Prompt. In most cases a Start Prompt should be provided although you may provide a `null` value in cases where you are not waiting for SSH server data but want the command to be executed immediately.
  See Also:
    Serialized Form

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static interface` | `SshTask.Listener`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `ACTIVE` SshTask is active and waiting for start prompt to execute command
    `static int` | `COMPLETE` SshTask has finished execution of command and has received end prompt
    `static int` | `PENDING` SshTask is waiting to be activated
    `static int` | `RUNNING` SshTask has received start prompt and is currently executing command

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `SshTask(java.lang.String name, java.lang.String promptPattern, boolean promptPatternIsRegex, java.lang.String command, java.lang.String responsePattern, boolean responsePatternIsRegex)`
    `SshTask(java.lang.String name, java.lang.String promptPattern, boolean promptPatternIsRegex, java.lang.String command, java.lang.String responsePattern, boolean responsePatternIsRegex, int regexMatchLength, java.lang.String endOfLine, java.lang.String characterSet, long promptTimeout, long responseTimeout)`
    `SshTask(java.lang.String promptPattern, java.lang.String command, java.lang.String responsePattern)` Constructs a new `SshTask` instance.
    `SshTask(java.lang.String name, java.lang.String promptPattern, java.lang.String command, java.lang.String responsePattern)` Constructs a new `SshTask` instance.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `activate(SshTask.Listener listener, java.io.OutputStream out, java.lang.String previousTaskResponse, java.lang.String endOfLine)`
    `void` | `cancel()` Cancels this task and subsequent tasks by setting it's status to complete.
    `java.lang.String` | `getCharacterSet()` Gets the character set
    `java.lang.String` | `getCommand()` Gets the command to execute
    `boolean` | `getDebug()` Checks whether debugging is enabled for this task.
    `java.io.PrintStream` | `getDebugStream()` Gets debug stream used when printing debug messages.
    `java.lang.String` | `getEndPrompt()` Gets the end shell prompt this `SshTask` should wait for to indicate that this `SshTask` is complete.
    `long` | `getEndPromptTimeout()` Gets the maximum timeout between the time the task is in running state and the expected end prompt is received.
    `java.lang.Exception` | `getError()`
    `java.lang.String` | `getName()` Gets name of this `SshTask` as defined in constructor.
    `int` | `getRegexMatchLength()` Gets the number of characters to read from the end of the response buffer when using regular expressions to detect start or end prompts.
    `java.lang.String` | `getResponse()` Gets response to command executed.
    `java.lang.String` | `getStartPrompt()` Gets the shell prompt this `SshTask` should wait for before executing command.
    `long` | `getStartPromptTimeout()` Gets the maximum timeout between the time the task is in active state and the expected start prompt is received.
    `int` | `getStatus()` Gets completion status of this `SshTask`.
    `java.lang.String` | `getStatusString(int status)` Gets status string based on task status
    `java.lang.String` | `getTerminator()` Gets line terminator used when sending commands.
    `boolean` | `isActive()` Checks if this `SshTask` is active.
    `boolean` | `isComplete()` Checks if this `SshTask` is complete.
    `boolean` | `isEndPromptRegex()` Checks if end prompt is a regular expression
    `boolean` | `isPending()` Checks if this `SshTask` is pending activation.
    `boolean` | `isRunning()` Checks if this `SshTask` is running.
    `boolean` | `isStartPromptRegex()` Specified if start prompt is a regular expression
    `boolean` | `isTimedOut()` Checks if task has exceeded timeout
    `void` | `onData(char data)`
    `void` | `onEof()`
    `void` | `setCharacterSet(java.lang.String value)` Sets character set used when write data
    `void` | `setDebug(boolean value)` Enables/disables additional debugging for this task.
    `void` | `setDebugStream(java.io.PrintStream value)` Sets debug stream to be used when printing debug messages.
    `void` | `setEndPromptRegex(boolean value)` Specifies if end prompt is a regular expression
    `void` | `setEndPromptTimeout(long value)` Sets the maximum timeout between the time the task is in running state and the expected end prompt is received.
    `void` | `setRegexMatchLength(int value)` Sets the number of characters to read from the end of the response buffer when using regular expressions to detect start or end prompts.
    `void` | `setStartPromptRegex(boolean value)` Specifies if start prompt is a regular expression
    `void` | `setStartPromptTimeout(long value)` Sets the maximum timeout between the time the task is in active state and the expected start prompt is received.
    `void` | `setTerminator(java.lang.String value)` Sets line terminator used when sending commands.

    - ### Methods inherited from class java.lang.Object

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

- - ### Field Detail

    - #### PENDING

          public static final int PENDING

      SshTask is waiting to be activated
      See Also:
        Constant Field Values

    - #### ACTIVE

          public static final int ACTIVE

      SshTask is active and waiting for start prompt to execute command
      See Also:
        Constant Field Values

    - #### RUNNING

          public static final int RUNNING

      SshTask has received start prompt and is currently executing command
      See Also:
        Constant Field Values

    - #### COMPLETE

          public static final int COMPLETE

      SshTask has finished execution of command and has received end prompt
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### SshTask

          public SshTask(java.lang.String name,
                         java.lang.String promptPattern,
                         boolean promptPatternIsRegex,
                         java.lang.String command,
                         java.lang.String responsePattern,
                         boolean responsePatternIsRegex,
                         int regexMatchLength,
                         java.lang.String endOfLine,
                         java.lang.String characterSet,
                         long promptTimeout,
                         long responseTimeout)

    - #### SshTask

          public SshTask(java.lang.String name,
                         java.lang.String promptPattern,
                         boolean promptPatternIsRegex,
                         java.lang.String command,
                         java.lang.String responsePattern,
                         boolean responsePatternIsRegex)

    - #### SshTask

          public SshTask(java.lang.String name,
                         java.lang.String promptPattern,
                         java.lang.String command,
                         java.lang.String responsePattern)

      Constructs a new `SshTask` instance.
      Parameters:
        `name` - a name to uniquely identify this `SshTask`.
        `promptPattern` - the shell prompt this task should wait for before executing command.
        `command` - the command to execute
        `responsePattern` - the end shell prompt this task should wait for to indicate that this task is finished.

    - #### SshTask

          public SshTask(java.lang.String promptPattern,
                         java.lang.String command,
                         java.lang.String responsePattern)

      Constructs a new `SshTask` instance.
      Parameters:
        `promptPattern` - the start data this task should wait for before executing command.
        `command` - the command to execute
        `responsePattern` - the end data this task should wait for to indicate that this task is finished.

  - ### Method Detail

    - #### getName

          public java.lang.String getName()

      Gets name of this `SshTask` as defined in constructor.
      Returns:
        name of this `SshTask`, `Unknown` if not defined.

    - #### getStartPrompt

          public java.lang.String getStartPrompt()

      Gets the shell prompt this `SshTask` should wait for before executing command.
      Returns:
        the start shell prompt

    - #### isStartPromptRegex

          public boolean isStartPromptRegex()

      Specified if start prompt is a regular expression
      Returns:
        true if is a regular expression, false otherwise

    - #### setStartPromptRegex

          public void setStartPromptRegex(boolean value)

      Specifies if start prompt is a regular expression
      Parameters:
        `value` - true if start prompt is a regular expression, false otherwise
      Throws:
        `SshException` - if the start prompt is an invalid regular expression
      See Also:
        `setRegexMatchLength(int)`

    - #### getCommand

          public java.lang.String getCommand()

      Gets the command to execute
      Returns:
        the command to execute

    - #### getEndPrompt

          public java.lang.String getEndPrompt()

      Gets the end shell prompt this `SshTask` should wait for to indicate that this `SshTask` is complete.
      Returns:
        the end shell prompt

    - #### isEndPromptRegex

          public boolean isEndPromptRegex()

      Checks if end prompt is a regular expression
      Returns:
        true if is a regular expression, false otherwise

    - #### setEndPromptRegex

          public void setEndPromptRegex(boolean value)

      Specifies if end prompt is a regular expression
      Parameters:
        `value` - true if end prompt is a regular expression, false otherwise
      Throws:
        `SshException` - if the end prompt is an invalid regular expression
      See Also:
        `setRegexMatchLength(int)`

    - #### getRegexMatchLength

          public int getRegexMatchLength()

      Gets the number of characters to read from the end of the response buffer when using regular expressions to detect start or end prompts. Default value is 20.
      Returns:
        match length

    - #### setRegexMatchLength

          public void setRegexMatchLength(int value)

      Sets the number of characters to read from the end of the response buffer when using regular expressions to detect start or end prompts. Default value is 20.
      Parameters:
        `value` -

    - #### getTerminator

          public java.lang.String getTerminator()

      Gets line terminator used when sending commands. Default is LF (Line Feed).
      Returns:
        line terminator

    - #### setTerminator

          public void setTerminator(java.lang.String value)

      Sets line terminator used when sending commands. Default is LF (Line Feed).
      Parameters:
        `value` - line terminator

    - #### setCharacterSet

          public void setCharacterSet(java.lang.String value)

      Sets character set used when write data
      Parameters:
        `value` - the character set

    - #### getCharacterSet

          public java.lang.String getCharacterSet()

      Gets the character set
      Returns:
        The character set used

    - #### getStartPromptTimeout

          public long getStartPromptTimeout()

      Gets the maximum timeout between the time the task is in active state and the expected start prompt is received.
      Returns:
        the timeout in milliseconds

    - #### setStartPromptTimeout

          public void setStartPromptTimeout(long value)

      Sets the maximum timeout between the time the task is in active state and the expected start prompt is received.
      Parameters:
        `value` - the timeout in milliseconds

    - #### getEndPromptTimeout

          public long getEndPromptTimeout()

      Gets the maximum timeout between the time the task is in running state and the expected end prompt is received.
      Returns:
        the timeout in milliseconds

    - #### setEndPromptTimeout

          public void setEndPromptTimeout(long value)

      Sets the maximum timeout between the time the task is in running state and the expected end prompt is received.
      Parameters:
        `value` - the timeout in milliseconds

    - #### getDebug

          public boolean getDebug()

      Checks whether debugging is enabled for this task.
      Returns:
        true if enabled, false otherwise

    - #### setDebug

          public void setDebug(boolean value)

      Enables/disables additional debugging for this task.
      Parameters:
        `value` - true if debugging is enabled, false otherwise

    - #### setDebugStream

          public void setDebugStream(java.io.PrintStream value)

      Sets debug stream to be used when printing debug messages. Default debug stream is System.out
      Parameters:
        `value` - a PrintStream

    - #### getDebugStream

          public java.io.PrintStream getDebugStream()

      Gets debug stream used when printing debug messages. Default debug stream is System.out
      Returns:
        a PrintStream

    - #### getStatus

          public int getStatus()

      Gets completion status of this `SshTask`.
      Returns:
        the completion status of this `SshTask`
      See Also:
        `PENDING`, `ACTIVE`, `RUNNING`, `COMPLETE`

    - #### getStatusString

          public java.lang.String getStatusString(int status)

      Gets status string based on task status
      Parameters:
        `status` - the status code
      Returns:
        the status
      See Also:
        `PENDING`, `ACTIVE`, `RUNNING`, `COMPLETE`

    - #### isPending

          public boolean isPending()

      Checks if this `SshTask` is pending activation.
      Returns:
        `true` if pending activation, `false` otherwise

    - #### isActive

          public boolean isActive()

      Checks if this `SshTask` is active.
      Returns:
        `true` if active, `false` otherwise

    - #### isRunning

          public boolean isRunning()

      Checks if this `SshTask` is running.
      Returns:
        `true` if running, `false` otherwise

    - #### isComplete

          public boolean isComplete()

      Checks if this `SshTask` is complete.
      Returns:
        `true` if complete, `false` otherwise

    - #### getResponse

          public java.lang.String getResponse()

      Gets response to command executed. Response will be empty if command has not executed.
      Returns:
        the response to command executed
      See Also:
        `isComplete()`

    - #### isTimedOut

          public boolean isTimedOut()

      Checks if task has exceeded timeout
      Returns:
        true if timeout exceeded, false otherwise

    - #### getError

          public java.lang.Exception getError()

    - #### activate

          public void activate(SshTask.Listener listener,
                               java.io.OutputStream out,
                               java.lang.String previousTaskResponse,
                               java.lang.String endOfLine)

    - #### onData

          public void onData(char data)

    - #### onEof

          public void onEof()

    - #### cancel

          public void cancel()

      Cancels this task and subsequent tasks by setting it's status to complete.

Copyright © JSCAPE LLC. 1999-2021. All Rights Reserved