public class Rexec
extends java.lang.Object
implements java.io.Serializable
Rexec rexec = new Rexec("remote.host.com", "johndoe", "SeCrEt","ls -la", false); try { rexec.connect(); rexec.execute(); InputStream input = rexec.getInputStream(); int in = input.read(); StringBuffer buffer = new StringBuffer(); if(in == 0) { buffer.append("Success! Remote host returned: \n"); } else { buffer.append("Failure! Remote host returned: \n"); } while((in = input.read()) != -1) { buffer.append((char)in); } System.out.println(buffer.toString()); } catch(Exception e) { System.out.println(e); }
Constructor and Description |
---|
Rexec(boolean hasErrorStream)
Initializes the Rexec class with or without the error stream.
|
Rexec(java.lang.String remoteHost,
java.lang.String username,
java.lang.String password,
java.lang.String command,
boolean hasErrorStream)
Constructs the Rexec class and sets all the connection parameters.
|
Modifier and Type | Method and Description |
---|---|
void |
addBsdListener(BsdListener listener)
Adds Bsd event listener.
|
void |
clearProxySettings()
Clears proxy server values.
|
void |
connect()
Connects to the remote host, initializing streams that handle stdin and stdout.
|
void |
disconnect()
Disconnects from the server, and cleans up all associated connections.
|
void |
execute()
Executes command on the remote host.
|
java.util.Vector |
getBsdListeners()
Gets all BsdListener currently bound to this
Rexec instance. |
java.lang.String |
getCommand()
Gets the command to be sent to the remote host.
|
java.io.InputStream |
getErrorStream()
Returns the
InputStream from which the standard error of the remote
process can be read if a separate error stream is requested from
the remote host. |
java.io.InputStream |
getInputStream()
Returns the
InputStream from which the standard output of the remote
process can be read. |
java.io.OutputStream |
getOutputStream()
Returns the
OutputStream to which the standard input of the remote
process can be written to. |
java.lang.String |
getPassword()
Gets the password to be sent to the remote host.
|
int |
getPort()
Gets the port to be used to make the connection.
|
java.lang.String |
getRemoteHost()
Gets the name of the remote host.
|
int |
getTimeout()
Gets the timeout for opening connection to server.
|
java.lang.String |
getUsername()
Gets the username to be sent to the remote host.
|
boolean |
hasErrorStream()
Returns weather the Rexec object was initialized with or without
separate error stream.
|
void |
removeBsdListener(BsdListener listener)
Removes specified Bsd event listener.
|
void |
setCommand(java.lang.String command)
Sets the command to be sent to the remote host.
|
void |
setPassword(java.lang.String password)
Sets the password to be sent to the remote host.
|
void |
setPort(int port)
Sets the port to be used to make the connection.
|
void |
setProxyAuthentication(java.lang.String proxyUsername,
java.lang.String proxyPassword)
Sets the username and password to use when for authentication with
proxy server.
|
void |
setProxyHost(java.lang.String proxyHostname,
int proxyPort)
Sets the proxy hostname and port for this connection.
|
void |
setProxyType(java.lang.String proxyType)
Sets the proxy type will be used for this connection.
|
void |
setRemoteHost(java.lang.String remoteHost)
Sets the name of the remote host to cennect to.
|
void |
setTimeout(int timeout)
Sets the timeout for opening connection to server.
|
void |
setUsername(java.lang.String username)
Sets the username to be sent to the remote host.
|
public Rexec(boolean hasErrorStream)
Rexec(true)
or together
with stdout - Rexec(false)
.
All other connection parameters are initialized to an empty String
hasErrorStream
- If true
, initialize separate error streampublic Rexec(java.lang.String remoteHost, java.lang.String username, java.lang.String password, java.lang.String command, boolean hasErrorStream)
remoteHost
- the Internet name of the remote host.username
- the username of the user, whose credentials are to be used to execute the command
.password
- the password associated with username
.command
- the command with arguments, to execute.hasErrorStream
- if true, remote host's stderr will be outputted through
separate error stream. If false, stderr will be outputted
along with stdout stream.public java.io.InputStream getInputStream()
InputStream
from which the standard output of the remote
process can be read. The input stream will be set after connect()
method invocation.
InputStream
from which the standard output of the remote
process can be read. Until the connect()
method has been invoked,
null
will be returned.public java.io.OutputStream getOutputStream()
OutputStream
to which the standard input of the remote
process can be written to. The output stream will be set after connect()
method invocation.
OutputStream
from which the standard input of the remote
process can be written. Until the connect()
method has been invoked,
null
will be returned.public java.io.InputStream getErrorStream()
InputStream
from which the standard error of the remote
process can be read if a separate error stream is requested from
the remote host. The error stream will only be set after a successful
execute()
invocation.
InputStream
from which the standard error of the remote
process can be read if a separate error stream is requested from
the server. Otherwise, null
will be returned.public void execute() throws BsdException
InputStream
, returned by
getInputStream()
If Rexec object was constructed with separate error stream, remote
host will return all stderr output through that stream. Separate
error stream is available through an InputStream
, returned by
getInputStream()
BsdException
- if the execute()
fails.getInputStream()
public void connect() throws BsdException
BsdException
- if an error occurs while connecting.public void disconnect() throws BsdException
BsdException
- if an error occurs while disconnecting.public void addBsdListener(BsdListener listener)
listener
- the listener to addBsdListener
public void removeBsdListener(BsdListener listener)
listener
- the listener to removeBsdListener
public java.util.Vector getBsdListeners()
Rexec
instance.Vector
of BsdListener
BsdListener
public void setRemoteHost(java.lang.String remoteHost)
remoteHost
- the remote host to connect topublic java.lang.String getRemoteHost()
public void setTimeout(int timeout)
timeout
- the timeout in millisecondspublic int getTimeout()
public void setPort(int port) throws BsdException
BsdException
is thrown.port
- the port to be used to make the connection.BsdException
- if port is invalidpublic int getPort()
public void setUsername(java.lang.String username)
username
- the username to be sent to the remote host.public java.lang.String getUsername()
public void setPassword(java.lang.String password)
password
- the password to be sent to the remote host.public java.lang.String getPassword()
public void setCommand(java.lang.String command)
command
- the command to be sent to the remote host.public java.lang.String getCommand()
public void setProxyAuthentication(java.lang.String proxyUsername, java.lang.String proxyPassword)
#clearProxySettings
method.proxyUsername
- the proxy usernameproxyPassword
- the proxy passwordclearProxySettings()
public void setProxyHost(java.lang.String proxyHostname, int proxyPort)
#clearProxySettings
method.proxyHostname
- the hostname or ip address of the proxy serverproxyPort
- the port of the proxy serverclearProxySettings()
public void setProxyType(java.lang.String proxyType)
proxyType
- The proxy type. Valid values: HTTP, SOCKS5public void clearProxySettings()
public boolean hasErrorStream()
true
if there is a separate error stream false
otherwiseCopyright © JSCAPE LLC. 1999-2021. All Rights Reserved