com.jscape.inet.ssh

## Class SshScript

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

- All Implemented Interfaces:
    SshListener, SshTask.Listener, java.io.Serializable

      public class SshScript
      extends java.lang.Object
      implements SshListener, SshTask.Listener, java.io.Serializable

  The SshScript class provides a simple way of running a set of batch scripted commands against a SSH server. When communicating with a SSH server in interactive mode (non-batch) the user must wait until the completion of the previous command before entering a new command. In interactive mode the completion of the previous command is generally indicated by the display of the shell prompt which allows the user to enter the next command. The SshScript class is especially useful in automating SSH procedures such as user login and command execution.

  For simple scripting tasks see the `SshSession` class.

  Example Usage:

       // create new Ssh instance
       Ssh Ssh = new Ssh(hostname,username,password);

       // create new SshScript instance
       SshScript script = new SshScript(Ssh);

       // create task to perform a directory listing

       SshTask dirListing = new SshTask("$","ls -al","$");

       // add task to script
       script.addTask(dirListing);

       // connect to SSH server and execute SshScript
       ssh.connect();

       // disconnect from SSH server
       ssh.disconnect();

  See Also:
    `SshSession`, Serialized Form

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `SshScript(Ssh ssh)` Constructs a new SshScript instance.
    `SshScript(Ssh ssh, java.lang.String endOfLine)` Constructs a new SshScript instance.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addSshScriptListener(SshScriptListener listener)` Adds a `SshScriptListener` to this `SshScript`.
    `void` | `addTask(SshTask task)` Adds a SshTask to this SshScript.
    `void` | `clear()` Clears all tasks from the script.
    `void` | `connected(SshConnectedEvent event)` Invoked when SSH connection is established.
    `void` | `dataReceived(SshDataReceivedEvent event)` Invoked when data is received from SSH server.
    `void` | `disconnected(SshDisconnectedEvent event)` Invoked when SSH connection is released.
    `SshTask` | `getTask(java.lang.String name)` Gets the named SshTask based on the name attribute of a SshTask.
    `boolean` | `isComplete()` Checks whether this SshScript has completed execution of all SshTask.
    `boolean` | `isEmpty()` Checks if there are any SshTask bound to this SshScript
    `void` | `onTaskCancelled(SshTask task)`
    `void` | `onTaskCompleted(SshTask task)`
    `void` | `onTaskError(SshTask task, java.lang.Exception error)`
    `void` | `onTaskTimeout(SshTask task)`
    `void` | `removeSshScriptListener(SshScriptListener listener)` Removes a `SshScriptListener` from this SshScript

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

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

- - ### Constructor Detail

    - #### SshScript

          public SshScript(Ssh ssh,
                           java.lang.String endOfLine)

      Constructs a new SshScript instance. When adding a new SshTask using addTask method the SshTask#setTerminator method is invoked with the terminator value. This is a convenient method of setting the terminator globally for all SshTask added to a SshScript instead of setting it for each SshTask.
      Parameters:
        `ssh` - - Ssh instance this SshScript is bound to.
        `endOfLine` - the line terminator to use when executing command for a SshTask
      See Also:
        `Ssh`, `SshTask`, `addTask(com.jscape.inet.ssh.SshTask)`

    - #### SshScript

          public SshScript(Ssh ssh)

      Constructs a new SshScript instance.
      Parameters:
        `ssh` - - the Ssh instance this SshScript is bound to.
      See Also:
        `Ssh`

  - ### Method Detail

    - #### addTask

          public void addTask(SshTask task)

      Adds a SshTask to this SshScript.
      Parameters:
        `task` - the SshTask to add
      See Also:
        `SshTask`

    - #### getTask

          public SshTask getTask(java.lang.String name)

      Gets the named SshTask based on the name attribute of a SshTask.
      Parameters:
        `name` - the name of the SshTask to retrieve.
      Returns:
        the named SshTask if found, null otherwise
      See Also:
        `SshTask`

    - #### isEmpty

          public boolean isEmpty()

      Checks if there are any SshTask bound to this SshScript
      Returns:
        true if there are SshTask, false otherwise

    - #### isComplete

          public boolean isComplete()

      Checks whether this SshScript has completed execution of all SshTask.
      Returns:
        true if all tasks executed, false otherwise

    - #### clear

          public void clear()

      Clears all tasks from the script.

    - #### addSshScriptListener

          public void addSshScriptListener(SshScriptListener listener)

      Adds a `SshScriptListener` to this `SshScript`.
      Parameters:
        `listener` - the `SshScriptListener` instance to add
      See Also:
        `SshScriptListener`

    - #### removeSshScriptListener

          public void removeSshScriptListener(SshScriptListener listener)

      Removes a `SshScriptListener` from this SshScript
      Parameters:
        `listener` - the `SshScriptListener` instance to remove
      See Also:
        `SshScriptListener`

    - #### connected

          public void connected(SshConnectedEvent event)

      Description copied from interface: `SshListener`
      Invoked when SSH connection is established.
      Specified by:
        `connected` in interface `SshListener`
      Parameters:
        `event` - a SshConnectedEvent
      See Also:
        `SshConnectedEvent`

    - #### disconnected

          public void disconnected(SshDisconnectedEvent event)

      Description copied from interface: `SshListener`
      Invoked when SSH connection is released.
      Specified by:
        `disconnected` in interface `SshListener`
      Parameters:
        `event` - a SshDisconnectedEvent
      See Also:
        `SshDisconnectedEvent`

    - #### dataReceived

          public void dataReceived(SshDataReceivedEvent event)

      Description copied from interface: `SshListener`
      Invoked when data is received from SSH server.
      Specified by:
        `dataReceived` in interface `SshListener`
      Parameters:
        `event` - a SshDataReceivedEvent

    - #### onTaskCompleted

          public void onTaskCompleted(SshTask task)

      Specified by:
        `onTaskCompleted` in interface `SshTask.Listener`

    - #### onTaskCancelled

          public void onTaskCancelled(SshTask task)

      Specified by:
        `onTaskCancelled` in interface `SshTask.Listener`

    - #### onTaskError

          public void onTaskError(SshTask task,
                                  java.lang.Exception error)

      Specified by:
        `onTaskError` in interface `SshTask.Listener`

    - #### onTaskTimeout

          public void onTaskTimeout(SshTask task)

      Specified by:
        `onTaskTimeout` in interface `SshTask.Listener`

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