|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectverinec.util.AbstractProgramExec
verinec.util.SshProgramExec
public class SshProgramExec
Wrapper methods for execution of native programs on any system using ssh.
Currently always uses J2ssh.
todo: we should make this more flexible. J2ssh is not very stable, maybe there are better implementations.
See J2sshProcess for details about the J2ssh limitations.
These methods provide for simpler program execution, allowing to redirect program output or input to files (the < / > parameters in a shell), or retrieving the output as a stream. They allow to set a timeout after which program execution is interrupted.
You can execute a program and wait for its result, or execute it asynchronous, that is in a separate thread without waiting for it to finish.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class verinec.util.AbstractProgramExec |
|---|
AbstractProgramExec.StreamGobbler, AbstractProgramExec.TimeoutWatcher |
| Field Summary | |
|---|---|
private String |
host
Hostname to connect to |
private String |
hostVerification
Requirement for host verification. |
private File |
keyfile
The path to file containing the private keys. |
private String |
passphrase
The passphrase to use with the key file. |
private String |
password
The password to use for password authentication. |
private int |
port
A port number to use, pass -1 to leave default |
private String |
prefPublicKey
The preferred public key algorithm. |
private String |
username
The username to log into the remote system. |
| Fields inherited from class verinec.util.AbstractProgramExec |
|---|
cwd, timedOut |
| Constructor Summary | |
|---|---|
SshProgramExec(String commandline,
File cwd,
InputStream stdin,
OutputStream stdout,
OutputStream stderr,
String host,
int port,
String username,
String password,
String prefPublicKey,
File keyfile,
String passphrase,
String hostVerification)
Prepare a program execution. |
|
| Method Summary | |
|---|---|
static int |
execSync(String commandline,
File cwd,
InputStream stdin,
OutputStream stdout,
OutputStream stderr,
int timeout,
String host,
int port,
String username,
String password,
String prefPublicKey,
File keyfile,
String passphrase,
String hostVerification)
Execute a program and wait for it to terminate. |
protected Process |
startProcess(String commandline,
File cwd)
Instantiate a process using Runtime. |
| Methods inherited from class verinec.util.AbstractProgramExec |
|---|
abortExecution, execAsync, execSync, exitValue, hasFinished |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private String host
private int port
private String username
private String password
private String prefPublicKey
private File keyfile
private String passphrase
private String hostVerification
| Constructor Detail |
|---|
public SshProgramExec(String commandline,
File cwd,
InputStream stdin,
OutputStream stdout,
OutputStream stderr,
String host,
int port,
String username,
String password,
String prefPublicKey,
File keyfile,
String passphrase,
String hostVerification)
The input for the program can be given as an InputStream that will be piped to the program as stdin. If you have a file as input, you can use java.io.FileInputStream. stdin can be null, in which case no input is given to the program.
The output can be pushed into OutputStreams for later treatment. If both streams are null, output is discarded. If the stdout stream is null only, errors are written into stderr, if stderr is null, both out and err written into stdout. Again, you can use FileOutputStream to write into files. The streams will be closed when the program execution is finished.
It is recommended to wrap the output streams with a BufferedOutputStream to avoid delays.
commandline - Name of the executable with all parameters. (Do not forget full path if executable is not in the path for programs).cwd - The current working directory directory for the new process (defaults to the system property user.dir if null).stdin - A Stream that will be fed to the process as input (ignored if null).stdout - A Stream to write the program output into (discarded if null).stderr - A Stream to write the program error output into (redirected to stdout if null).host - Hostname to connect toport - A port number to use, pass -1 to leave defaultusername - The username to log into the remote system.password - The password to use for password authentication. If null, no password auth is attempted.prefPublicKey - The preferred public key algorithm. 'ssh-rsa' is a good choice.keyfile - The path to file containing the private keys. If null, no public key auth is attempted.passphrase - The passphrase to use with the key file. Pass null if no pass phrase needed.hostVerification - Requirement for host verification.
Possible values are ignore, interactive or the expected host fingerprint.| Method Detail |
|---|
public static int execSync(String commandline,
File cwd,
InputStream stdin,
OutputStream stdout,
OutputStream stderr,
int timeout,
String host,
int port,
String username,
String password,
String prefPublicKey,
File keyfile,
String passphrase,
String hostVerification)
throws InterruptedException,
VerinecException
The input for the program can be given as an InputStream that will be piped to the program as stdin. If you have a file as input, you can use java.io.FileInputStream. stdin can be null, in which case no input is given to the program.
The output can be pushed into OutputStreams for later treatment. If both streams are null, output is discarded. If the stdout stream is null only, errors are written into stderr, if stderr is null, both out and err written into stdout. Again, you can use FileOutputStream to write into files. The streams will be closed when the program execution is finished.
It is recommended to wrap the output streams with a BufferedOutputStream to avoid delays.
commandline - Name of the executable with all parameters. (Do not forget full path if executable is not in the path for programs).cwd - The current working directory directory for the new process (defaults to the system property user.dir if null).stdin - A Stream that will be fed to the process as input (ignored if null).stdout - A Stream to write the program output into (discarded if null).stderr - A Stream to write the program error output into (redirected to stdout if null).timeout - The time in seconds after which the execution should be interrupted (0 for no timeout).host - Hostname to connect toport - A port number to use, pass -1 to leave defaultusername - The username to log into the remote system.password - The password to use for password authentication. If null, no password auth is attempted.prefPublicKey - The preferred public key algorithm. 'ssh-rsa' is a good choice.keyfile - The path to file containing the private keys. If null, no public key auth is attempted.passphrase - The passphrase to use with the key file. Pass null if no pass phrase needed.hostVerification - Requirement for host verification.
InterruptedException - If the timeout occurs or the process is otherwise interrupted.
VerinecException - If other errors occur.
protected Process startProcess(String commandline,
File cwd)
throws VerinecException
startProcess in class AbstractProgramExeccommandline - The command line to execute.cwd - Current working directory on the target system.
VerinecException - If the specified command can not be executed.
|
Copyright © 2005 Verinec, DIUF | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||