de.mud.jta

Class Wrapper

Known Direct 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\u00dfner

Field Summary

protected String
host
protected InputStream
in
protected OutputStream
out
protected int
port
protected Vector
script
protected ScriptHandler
scriptHandler
protected Socket
socket

Method Summary

void
connect(String host, int port)
Connect the socket and open the connection.
void
disconnect()
Disconnect the socket and close the connection.
String
getPrompt()
String
getTerminalType()
Dimension
getWindowSize()
void
login(String user, String pwd)
Login into remote host.
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.
void
setLocalEcho(boolean echo)
void
setPrompt(String prompt)
String
waitfor(String match)
String
waitfor(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.

Field Details

host

protected String host

in

protected InputStream in

out

protected OutputStream out

port

protected int port

script

protected Vector script

scriptHandler

protected ScriptHandler scriptHandler

socket

protected Socket socket

Method Details

connect

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

disconnect

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

getPrompt

public String getPrompt()

getTerminalType

public String getTerminalType()

getWindowSize

public Dimension getWindowSize()

login

public void login(String user,
                  String pwd)
            throws 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

read

public int read(byte[] b)
            throws 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

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

setLocalEcho

public void setLocalEcho(boolean echo)

setPrompt

public void setPrompt(String prompt)

waitfor

public String waitfor(String match)
            throws IOException

waitfor

public String waitfor(String[] searchElements)
            throws 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:
Returns:
skipped characters

write

public void write(byte[] b)
            throws IOException
Write data to the socket.
Parameters:
b - the buffer to be written