de.mud.jta
Class Wrapper

java.lang.Object
  extended by de.mud.jta.Wrapper
Direct Known Subclasses:
SshWrapper, TelnetWrapper

public class Wrapper
extends java.lang.Object

To write a program using the wrapper you may use the following piece of code as an example:

   TelnetWrapper telnet = new TelnetWrapper();
   try {
     telnet.connect(args[0], 23);
     telnet.login("user", "password");
     telnet.setPrompt("user@host");
     telnet.waitfor("Terminal type?");
     telnet.send("dumb");
     System.out.println(telnet.send("ls -l"));
   } catch(java.io.IOException e) {
     e.printStackTrace();
   }
 
Please keep in mind that the password is visible for anyone who can download the class file. So use this only for public accounts or if you are absolutely sure nobody can see the file.

Maintainer: Matthias L. Jugel

Version:
$Id: Wrapper.java 499 2005-09-29 08:24:54Z leo $
Author:
Matthias L. Jugel, Marcus Mei?ner

Field Summary
protected  java.lang.String host
           
protected  java.io.InputStream in
           
protected  java.io.OutputStream out
           
protected  int port
           
protected  java.util.Vector script
           
protected  ScriptHandler scriptHandler
           
protected  java.net.Socket socket
           
 
Constructor Summary
Wrapper()
           
 
Method Summary
 void connect(java.lang.String host, int port)
          Connect the socket and open the connection.
 void disconnect()
          Disconnect the socket and close the connection.
 java.lang.String getPrompt()
           
 java.lang.String getTerminalType()
           
 java.awt.Dimension getWindowSize()
           
 void login(java.lang.String user, java.lang.String pwd)
          Login into remote host.
 int read(byte[] b)
          Read data from the socket and use telnet negotiation before returning the data read.
 java.lang.String send(java.lang.String cmd)
          Send a command to the remote host.
 void setLocalEcho(boolean echo)
           
 void setPrompt(java.lang.String prompt)
           
 java.lang.String waitfor(java.lang.String match)
           
 java.lang.String waitfor(java.lang.String[] searchElements)
          Wait for a string to come from the remote host and return all that characters that are received until that happens (including the string being waited for).
 void write(byte[] b)
          Write data to the socket.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

scriptHandler

protected ScriptHandler scriptHandler

in

protected java.io.InputStream in

out

protected java.io.OutputStream out

socket

protected java.net.Socket socket

host

protected java.lang.String host

port

protected int port

script

protected java.util.Vector script
Constructor Detail

Wrapper

public Wrapper()
Method Detail

connect

public void connect(java.lang.String host,
                    int port)
             throws java.io.IOException
Connect the socket and open the connection.

Throws:
java.io.IOException

disconnect

public void disconnect()
                throws java.io.IOException
Disconnect the socket and close the connection.

Throws:
java.io.IOException

login

public void login(java.lang.String user,
                  java.lang.String pwd)
           throws java.io.IOException
Login into remote host. This is a convenience method and only works if the prompts are "login:" and "Password:".

Parameters:
user - the user name
pwd - the password
Throws:
java.io.IOException

setPrompt

public void setPrompt(java.lang.String prompt)

getPrompt

public java.lang.String getPrompt()

send

public java.lang.String send(java.lang.String cmd)
                      throws java.io.IOException
Send a command to the remote host. A newline is appended and if a prompt is set it will return the resulting data until the prompt is encountered.

Parameters:
cmd - the command
Returns:
output of the command or null if no prompt is set
Throws:
java.io.IOException

waitfor

public java.lang.String waitfor(java.lang.String[] searchElements)
                         throws java.io.IOException
Wait for a string to come from the remote host and return all that characters that are received until that happens (including the string being waited for).

Parameters:
match - the string to look for
Returns:
skipped characters
Throws:
java.io.IOException

waitfor

public java.lang.String waitfor(java.lang.String match)
                         throws java.io.IOException
Throws:
java.io.IOException

read

public int read(byte[] b)
         throws java.io.IOException
Read data from the socket and use telnet negotiation before returning the data read.

Parameters:
b - the input buffer to read in
Returns:
the amount of bytes read
Throws:
java.io.IOException

write

public void write(byte[] b)
           throws java.io.IOException
Write data to the socket.

Parameters:
b - the buffer to be written
Throws:
java.io.IOException

getTerminalType

public java.lang.String getTerminalType()

getWindowSize

public java.awt.Dimension getWindowSize()

setLocalEcho

public void setLocalEcho(boolean echo)