Class TelnetWrapper
Class TelnetWrapper
java.lang.Object
|
+----TelnetWrapper
- public class TelnetWrapper
- extends Object
Wrapper for a Java Telnet call.
Supports remote commands.
Uses code from Matthias L. Jugel's and Marcus Meißner's freeware
Telnet Applet.
Note - their Applet is under GNU copyleft, so any commercial use of
this code is restricted. See their above site for details.
- Author:
- George Ruban 3/4/97
- See Also:
- TelnetIO
-
tio
- The telnet connection.
-
TelnetWrapper(String)
- Connects to the default telnet port on the given host.
-
disconnect()
- Ends the telnet connection.
-
finalize()
- Ends the telnet connection.
-
login(String, String)
- Logs in as a particular user and password.
-
main(String[])
- Telnet test driver.
-
receive()
- Returns a String from the telnet connection.
-
receiveBytes()
- Returns a byte array.
-
receiveUntil(String)
- Returns all data received up until a certain token.
-
send(byte[])
- Sends bytes over the telnet connection.
-
send(String)
- Sends a String to the remote host.
-
sendLine(String)
- Sends a line to the remote host, returns all data before the prompt.
-
setDefaultPrompt(String)
- Sets the default prompt used by all TelnetWrappers.
-
setLogin(String, String)
- Sets the default login used by TelnetWrappers.
-
setPrompt(String)
- Sets the expected prompt.
-
unsetLogin()
- Turns off the default login of TelnetWrappers.
-
wait(String)
- Skip any received data until the token appears.
tio
protected TelnetIO tio
- The telnet connection. That which is wrapped.
TelnetWrapper
public TelnetWrapper(String host) throws IOException
- Connects to the default telnet port on the given host.
wait
public void wait(String token) throws IOException
- Skip any received data until the token appears.
receive
public String receive() throws IOException
- Returns a String from the telnet connection. Blocks
until one is available. No guarantees that the string is in
any way complete.
NOTE: uses Java 1.0.2 style String-bytes conversion.
receiveBytes
public byte[] receiveBytes() throws IOException
- Returns a byte array. Blocks until data is available.
receiveUntil
public String receiveUntil(String token) throws IOException
- Returns all data received up until a certain token.
send
public void send(String s) throws IOException
- Sends a String to the remote host.
NOTE: uses Java 1.0.2 style String-bytes conversion.
sendLine
public String sendLine(String command) throws IOException
- Sends a line to the remote host, returns all data before the prompt.
Since telnet seems to rely on carriage returns ('\r'),
one will be appended to the sent string, if necessary.
- Parameters:
- command - command line to send
- Returns:
- whatever data the command produced before the prompt.
- See Also:
- setPrompt
send
public void send(byte buf[]) throws IOException
- Sends bytes over the telnet connection.
login
public void login(String loginName,
String password) throws IOException
- Logs in as a particular user and password.
Returns after receiving prompt.
setPrompt
public void setPrompt(String prompt)
- Sets the expected prompt.
If this function is not explicitly called, the default prompt is used.
- See Also:
- setDefaultPrompt
setDefaultPrompt
public static void setDefaultPrompt(String prompt)
- Sets the default prompt used by all TelnetWrappers.
This can be specifically overridden for a specific instance.
The default prompt starts out as "$ " until this function is called.
- See Also:
- setPrompt
setLogin
public static void setLogin(String login,
String password)
- Sets the default login used by TelnetWrappers.
If this method is called with non-null login and password,
all TelnetWrappers will attempt to login when first created.
- Parameters:
- login - login name to use
- password - password to use
- See Also:
- login, unsetLogin
unsetLogin
public static void unsetLogin()
- Turns off the default login of TelnetWrappers.
After this method is called, TelnetWrappers will not
login until that method is explicitly called.
- See Also:
- setLogin, login
disconnect
public void disconnect() throws IOException
- Ends the telnet connection.
finalize
public void finalize()
- Ends the telnet connection.
- Overrides:
- finalize in class Object
main
public static void main(String args[]) throws IOException
- Telnet test driver.
Modeled after the IOtest.java example in the Telnet Applet.
Logs in to stems, creates a timestamped file in /tmp, lists the
/tmp directory to System.out, disconnects. Shows off several
TelnetWrapper methods.