de.mud.telnet
Class TelnetWrapper
public class TelnetWrapper
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
$Id: TelnetWrapper.java 499 2005-09-29 08:24:54Z leo $- Matthias L. Jugel, Marcus Mei???ner
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.
|
connect , disconnect , getPrompt , getTerminalType , getWindowSize , login , read , send , setLocalEcho , setPrompt , waitfor , waitfor , write |
TelnetWrapper
public TelnetWrapper()
connect
public void connect(String host,
int port)
throws IOException
Connect the socket and open the connection.
- connect in interface Wrapper
read
public int read(byte[] b)
throws IOException
Read data from the socket and use telnet negotiation before returning
the data read.
- read in interface Wrapper
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.
- send in interface Wrapper
- output of the command or null if no prompt is set