de.mud.ssh
Class SshWrapper

java.lang.Object
  |
  +--de.mud.ssh.SshWrapper

public class SshWrapper
extends java.lang.Object

The telnet ssh is a sample class for how to use the SSH 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:

   SshWrapper telnet = new SshWrapper();
   try {
     ssh.connect(args[0], 23);
     ssh.login("user", "password");
     ssh.setPrompt("user@host");
     ssh.waitfor("Terminal type?");
     ssh.send("dumb");
     System.out.println(ssh.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:Marcus Meissner

Version:
$Id: SshWrapper.java,v 1.3 2002/07/18 20:33:59 marcus Exp $
Author:
Matthias L. Jugel, Marcus Meißner

Field Summary
protected  SshIO handler
           
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 Summary
SshWrapper()
           
 
Method Summary
 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 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 backend and decrypt it.
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

handler

protected SshIO handler

scriptHandler

protected ScriptHandler scriptHandler

in

protected java.io.InputStream in

out

protected java.io.OutputStream out

socket

protected java.net.Socket socket

host

protected java.lang.String host

port

protected int port

script

protected java.util.Vector script
Constructor Detail

SshWrapper

public SshWrapper()
Method Detail

connect

public void connect(java.lang.String host,
                    int port)
             throws java.io.IOException
Connect the socket and open the connection.

disconnect

public void disconnect()
                throws java.io.IOException
Disconnect the socket and close the connection.

login

public void login(java.lang.String user,
                  java.lang.String pwd)
           throws java.io.IOException
Login into remote host. This is a convenience method and only works if the prompts are "login:" and "Password:".
Parameters:
user - the user name
pwd - the password

setPrompt

public void setPrompt(java.lang.String prompt)

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.
Parameters:
cmd - the command
Returns:
output of the command or null if no prompt is set

waitfor

public java.lang.String waitfor(java.lang.String[] searchElements)
                         throws java.io.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).
Parameters:
match - the string to look for
Returns:
skipped characters

waitfor

public java.lang.String waitfor(java.lang.String match)
                         throws java.io.IOException

read

public int read(byte[] b)
         throws java.io.IOException
Read data from the backend and decrypt it. This is a buffering read as the encrypted information is usually smaller than its decrypted pendant. So it will not read from the backend as long as there is data in the buffer.
Parameters:
b - the buffer where to read the decrypted data in
Returns:
the amount of bytes actually read.

write

public void write(byte[] b)
           throws java.io.IOException
Write data to the socket.
Parameters:
b - the buffer to be written

getTerminalType

public java.lang.String getTerminalType()

getWindowSize

public java.awt.Dimension getWindowSize()

setLocalEcho

public void setLocalEcho(boolean echo)