de.mud.telnet
Class TelnetWrapper
java.lang.Object
|
+--de.mud.jta.Wrapper
|
+--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,v 1.13 2003/04/26 12:33:29 marcus Exp $
- Author:
- Matthias L. Jugel, Marcus Meißner
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 java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
handler
protected TelnetProtocolHandler handler
TelnetWrapper
public TelnetWrapper()
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
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
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
java.io.IOException