de.mud.jta
Class Wrapper
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
$Id: Wrapper.java 499 2005-09-29 08:24:54Z leo $- Matthias L. Jugel, Marcus Mei\u00dfner
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.
|
host
protected String host
in
protected InputStream in
out
protected OutputStream out
script
protected Vector script
socket
protected Socket socket
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:".
user
- the user namepwd
- the password
read
public int read(byte[] b)
throws IOException
Read data from the socket and use telnet negotiation before returning
the data read.
b
- the input buffer to read in
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.
- 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).
write
public void write(byte[] b)
throws IOException
Write data to the socket.
b
- the buffer to be written