public class Rsh extends Rexec implements java.io.Serializable
Example Usage:
Rsh rsh = new Rsh("remote.host.com", "johndoe", "johndoe","ls -la", false); try { rsh.connect(); rsh.execute(); InputStream input = rsh.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 |
---|
Rsh(boolean hasErrorStream)
Initializes the Rsh object with port set to 514.
|
Rsh(java.lang.String remoteHost,
java.lang.String username,
java.lang.String localUsername,
java.lang.String command,
boolean hasErrorStream)
Initializes the Rsh object with port set to 514 and all connection
parameters.
|
Modifier and Type | Method and Description |
---|---|
void |
clearProxySettings()
Clears proxy server values.
|
void |
connect()
Initializes input and output streams to handle stdin and stdout of the
remote host.
|
void |
execute()
Executes a command through the rshd daemon on the remote host.
|
java.lang.String |
getLocalUsername()
Gets the local username to be sent to the remote host.
|
void |
setLocalUsername(java.lang.String localUsername)
Sets the username of the user originating 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.
|
addBsdListener, disconnect, getBsdListeners, getCommand, getErrorStream, getInputStream, getOutputStream, getPassword, getPort, getRemoteHost, getTimeout, getUsername, hasErrorStream, removeBsdListener, setCommand, setPassword, setPort, setRemoteHost, setTimeout, setUsername
public Rsh(boolean hasErrorStream)
hasErrorStream
- if true stderr will be processed through separate
streampublic Rsh(java.lang.String remoteHost, java.lang.String username, java.lang.String localUsername, 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
.localUsername
- the username of the user who is initiating the
connection.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 void connect() throws BsdException
connect
in class Rexec
BsdException
- if connection can not be established.public void execute() throws BsdException
InputStream
returned by getInputStream()
method. stdin can be accessed through an OutputStream
returned by getOutputStream()
. If separate stderr
processing is required, stderr can be read using an
InputStream
returned by getInputStream()
method.
To properly terminate connection, use disconnect()
method.
Beware that remote process will finish after EOF is sent to stdout, so
disconnecting too early will not terminate remote process.
execute
in class Rexec
BsdException
- if rsh negotiation fails.Rexec.getInputStream()
public void setLocalUsername(java.lang.String localUsername)
localUsername
- the local username to be sent to the remote host.public java.lang.String getLocalUsername()
public void setProxyAuthentication(java.lang.String proxyUsername, java.lang.String proxyPassword)
#clearProxySettings
method.setProxyAuthentication
in class Rexec
proxyUsername
- the proxy usernameproxyPassword
- the proxy passwordclearProxySettings()
public void setProxyHost(java.lang.String proxyHostname, int proxyPort)
#clearProxySettings
method.setProxyHost
in class Rexec
proxyHostname
- the hostname or ip address of the proxy serverproxyPort
- the port of the proxy serverclearProxySettings()
public void setProxyType(java.lang.String proxyType)
setProxyType
in class Rexec
proxyType
- The proxy type. Valid values: HTTP, SOCKS5public void clearProxySettings()
clearProxySettings
in class Rexec
Copyright © JSCAPE LLC. 1999-2021. All Rights Reserved