de.mud.ssh

Class SshWrapper


public class SshWrapper
extends Wrapper

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 Mei???ner

Version:
$Id: SshWrapper.java 499 2005-09-29 08:24:54Z leo $
Author:
Matthias L. Jugel, Marcus Mei???ner

Field Summary

protected SshIO
handler

Fields inherited from class de.mud.jta.Wrapper

host, in, out, port, script, scriptHandler, socket

Constructor Summary

SshWrapper()

Method Summary

int
read(byte[] b)
Read data from the backend and decrypt it.
String
send(String cmd)
Send a command to the remote host.

Methods inherited from class de.mud.jta.Wrapper

connect, disconnect, getPrompt, getTerminalType, getWindowSize, login, read, send, setLocalEcho, setPrompt, waitfor, waitfor, write

Field Details

handler

protected SshIO handler

Constructor Details

SshWrapper

public SshWrapper()

Method Details

read

public int read(byte[] b)
            throws 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.
Overrides:
read in interface Wrapper
Parameters:
b - the buffer where to read the decrypted data in
Returns:
the amount of bytes actually read.

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