de.mud.jta
public class Wrapper extends java.lang.Object
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
Modifier and Type | Field and Description |
---|---|
protected java.lang.String |
host |
protected java.io.InputStream |
in |
protected java.io.OutputStream |
out |
protected int |
port |
protected java.util.Vector |
script |
protected ScriptHandler |
scriptHandler |
protected java.net.Socket |
socket |
Constructor and Description |
---|
Wrapper() |
Modifier and Type | Method and Description |
---|---|
void |
connect(java.lang.String host,
int port)
Connect the socket and open the connection.
|
void |
disconnect()
Disconnect the socket and close the connection.
|
java.lang.String |
getPrompt() |
java.lang.String |
getTerminalType() |
java.awt.Dimension |
getWindowSize() |
void |
login(java.lang.String user,
java.lang.String pwd)
Login into remote host.
|
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.
|
void |
setLocalEcho(boolean echo) |
void |
setPrompt(java.lang.String prompt) |
java.lang.String |
waitfor(java.lang.String match) |
java.lang.String |
waitfor(java.lang.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.
|
protected ScriptHandler scriptHandler
protected java.io.InputStream in
protected java.io.OutputStream out
protected java.net.Socket socket
protected java.lang.String host
protected int port
protected java.util.Vector script
public void connect(java.lang.String host, int port) throws java.io.IOException
java.io.IOException
public void disconnect() throws java.io.IOException
java.io.IOException
public void login(java.lang.String user, java.lang.String pwd) throws java.io.IOException
user
- the user namepwd
- the passwordjava.io.IOException
public void setPrompt(java.lang.String prompt)
public java.lang.String getPrompt()
public java.lang.String send(java.lang.String cmd) throws java.io.IOException
cmd
- the commandjava.io.IOException
public java.lang.String waitfor(java.lang.String[] searchElements) throws java.io.IOException
match
- the string to look forjava.io.IOException
public java.lang.String waitfor(java.lang.String match) throws java.io.IOException
java.io.IOException
public int read(byte[] b) throws java.io.IOException
b
- the input buffer to read injava.io.IOException
public void write(byte[] b) throws java.io.IOException
b
- the buffer to be writtenjava.io.IOException
public java.lang.String getTerminalType()
public java.awt.Dimension getWindowSize()
public void setLocalEcho(boolean echo)