de.mud.telnet
Class TelnetWrapper

java.lang.Object
  extended by de.mud.jta.Wrapper
      extended by de.mud.telnet.TelnetWrapper

public class TelnetWrapper
extends Wrapper

The telnet wrapper is a sample class for how to use the telnet protocol handler of the JTA source package. 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: TelnetWrapper.java 499 2005-09-29 08:24:54Z leo $
Author:
Matthias L. Jugel, Marcus Mei???ner

Field Summary
protected  TelnetProtocolHandler handler
           
 
Fields inherited from class de.mud.jta.Wrapper
host, in, out, port, script, scriptHandler, socket
 
Constructor Summary
TelnetWrapper()
           
 
Method Summary
 void connect(java.lang.String host, int port)
          Connect the socket and open the connection.
 TelnetProtocolHandler getHandler()
           
 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.
 
Methods inherited from class de.mud.jta.Wrapper
disconnect, getPrompt, getTerminalType, getWindowSize, login, setLocalEcho, setPrompt, waitfor, waitfor, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

handler

protected TelnetProtocolHandler handler
Constructor Detail

TelnetWrapper

public TelnetWrapper()
Method Detail

getHandler

public TelnetProtocolHandler getHandler()

connect

public void connect(java.lang.String host,
                    int port)
             throws java.io.IOException
Description copied from class: Wrapper
Connect the socket and open the connection.

Overrides:
connect in class Wrapper
Throws:
java.io.IOException

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.

Overrides:
send in class Wrapper
Parameters:
cmd - the command
Returns:
output of the command or null if no prompt is set
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.

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