de.mud.telnet

Class 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(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.
String
send(String cmd)
Send a command to the remote host.

Methods inherited from class de.mud.jta.Wrapper

connect, disconnect, getPrompt, getTerminalType, getWindowSize, login, read, send, setLocalEcho, setPrompt, waitfor, waitfor, write

Field Details

handler

protected TelnetProtocolHandler handler

Constructor Details

TelnetWrapper

public TelnetWrapper()

Method Details

connect

public void connect(String host,
                    int port)
            throws IOException
Connect the socket and open the connection.
Overrides:
connect in interface Wrapper

getHandler

public TelnetProtocolHandler getHandler()

read

public int read(byte[] b)
            throws IOException
Read data from the socket and use telnet negotiation before returning the data read.
Overrides:
read in interface Wrapper
Parameters:
b - the input buffer to read in
Returns:
the amount of bytes read

send

public String send(String cmd)
            throws 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 interface Wrapper
Parameters:
cmd - the command
Returns:
output of the command or null if no prompt is set