SSH Factory

com.jscape.inet.telnet
Class TelnetScript

java.lang.Object
  extended by com.jscape.inet.telnet.TelnetScript
All Implemented Interfaces:
java.io.Serializable

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

The TelnetScript class provides a simple way of running a set of batch scripted commands against a TelnetServer. When communicating with a Telnet 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 TelnetScript class is especially useful in automating Telnet procedures such as user login and command execution.

Example Usage:

 // create new Telnet instance
 Telnet telnet = new Telnet("10.0.0.1");

 // create new TelnetScript instance
 TelnetScript script = new TelnetScript(telnet);

 // create task to automatically submit username
 TelnetTask username = new TelnetTask("login:","jsmith","Password:");

 // create task to automatically submit password
 TelnetTask password = new TelnetTask("Password:","secret","$");

 // create task to perform a directory listing

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

 // add tasks to script
 script.addTask(username);
 script.addTask(password);
 script.addTask(dirListing);

 // connect to Telnet server and execute TelnetScript
 telnet.connect();

 // disconnect from Telnet server
 telnet.disconnect();
 

See Also:
Serialized Form

Constructor Summary
TelnetScript(Telnet telnet)
          Constructs a new TelnetScript instance.
TelnetScript(Telnet telnet, java.lang.String terminator)
          Constructs a new TelnetScript instance.
 
Method Summary
 void addTask(TelnetTask task)
          Adds a TelnetTask to this TelnetScript.
 void addTelnetScriptListener(TelnetScriptListener listener)
          Adds a TelnetScriptListener to this TelnetScript.
 void clear()
          Clears all tasks from the script.
 TelnetTask getTask(java.lang.String name)
          Gets the named TelnetTask based on the name attribute of a TelnetTask.
 boolean isComplete()
          Checks whether this TelnetScript has completed execution of all TelnetTask.
 boolean isEmpty()
          Checks if there are any TelnetTask bound to this TelnetScript
 void removeTelnetScriptListener(TelnetScriptListener listener)
          Removes a TelnetScriptListener from this TelnetScript
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TelnetScript

public TelnetScript(Telnet telnet)
Constructs a new TelnetScript instance.

Parameters:
telnet - Telnet instance this TelnetScript is bound to.
See Also:
Telnet

TelnetScript

public TelnetScript(Telnet telnet,
                    java.lang.String terminator)
Constructs a new TelnetScript instance. When adding a new TelnetTask using addTask method the TelnetTask#setTerminator method is invoked with the terminator value. This is a convenient method of setting the terminator globally for all TelnetTask added to a TelnetScript instead of setting it for each TelnetTask.

Parameters:
telnet - Telnet instance this TelnetScript is bound to.
terminator - the line terminator to use when executing command for a TelnetTask
See Also:
Telnet, TelnetTask, addTask(com.jscape.inet.telnet.TelnetTask)
Method Detail

isEmpty

public boolean isEmpty()
Checks if there are any TelnetTask bound to this TelnetScript

Returns:
true if there are TelnetTask, false otherwise

clear

public void clear()
Clears all tasks from the script.


addTask

public void addTask(TelnetTask task)
Adds a TelnetTask to this TelnetScript.

Parameters:
task - the TelnetTask to add
See Also:
TelnetTask

getTask

public TelnetTask getTask(java.lang.String name)
Gets the named TelnetTask based on the name attribute of a TelnetTask.

Parameters:
name - the name of the TelnetTask to retrieve.
Returns:
the named TelnetTask if found, null otherwise
See Also:
TelnetTask

addTelnetScriptListener

public void addTelnetScriptListener(TelnetScriptListener listener)
Adds a TelnetScriptListener to this TelnetScript.

Parameters:
listener - the TelnetScriptListener instance to add
See Also:
TelnetScriptListener

removeTelnetScriptListener

public void removeTelnetScriptListener(TelnetScriptListener listener)
Removes a TelnetScriptListener from this TelnetScript

Parameters:
listener - the TelnetScriptListener instance to remove
See Also:
TelnetScriptListener

isComplete

public boolean isComplete()
Checks whether this TelnetScript has completed execution of all TelnetTask.

Returns:
true if all tasks executed, false otherwise

SSH Factory

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