com.jscape.inet.bsd

## Class Rsh

- java.lang.Object
- - com.jscape.inet.bsd.Rexec
  - - com.jscape.inet.bsd.Rsh

- All Implemented Interfaces:
    java.io.Serializable

      public class Rsh
      extends Rexec
      implements java.io.Serializable

  Implements the functionality of a BSD rsh client.

  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);
       }

  See Also:
    Serialized Form

- - ### Constructor Summary

    Constructors
    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.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    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.

    - ### Methods inherited from class com.jscape.inet.bsd.Rexec

      `addBsdListener, disconnect, getBsdListeners, getCommand, getErrorStream, getInputStream, getOutputStream, getPassword, getPort, getRemoteHost, getTimeout, getUsername, hasErrorStream, removeBsdListener, setCommand, setPassword, setPort, setRemoteHost, setTimeout, setUsername`

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### Rsh

          public Rsh(boolean hasErrorStream)

      Initializes the Rsh object with port set to 514. All connection parameters must be set using member functions.

      Parameters:
        `hasErrorStream` - if true stderr will be processed through separate stream

    - #### Rsh

          public 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.

      Parameters:
        `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.

  - ### Method Detail

    - #### connect

          public void connect()
                       throws BsdException

      Initializes input and output streams to handle stdin and stdout of the remote host. Before calling this method, all connection parameters must be set.
      Overrides:
        `connect` in class `Rexec`
      Throws:
        `BsdException` - if connection can not be established.

    - #### execute

          public void execute()
                       throws BsdException

      Executes a command through the rshd daemon on the remote host. After calling this method, stdout of the remote host is received through an `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.

      Overrides:
        `execute` in class `Rexec`
      Throws:
        `BsdException` - if rsh negotiation fails.
      See Also:
        `Rexec.getInputStream()`

    - #### setLocalUsername

          public void setLocalUsername(java.lang.String localUsername)

      Sets the username of the user originating the connection. Unix restrictions apply - only 8 characters are allowed. Any excess is removed.
      Parameters:
        `localUsername` - the local username to be sent to the remote host.

    - #### getLocalUsername

          public java.lang.String getLocalUsername()

      Gets the local username to be sent to the remote host.
      Returns:
        the local username to be sent to the remote host.

    - #### setProxyAuthentication

          public void setProxyAuthentication(java.lang.String proxyUsername,
                                             java.lang.String proxyPassword)

      Sets the username and password to use when for authentication with proxy server. To clear these settings invoke the `#clearProxySettings` method.
      Overrides:
        `setProxyAuthentication` in class `Rexec`
      Parameters:
        `proxyUsername` - the proxy username
        `proxyPassword` - the proxy password
      See Also:
        `clearProxySettings()`

    - #### setProxyHost

          public void setProxyHost(java.lang.String proxyHostname,
                                   int proxyPort)

      Sets the proxy hostname and port for this connection. To clear these settings invoke the `#clearProxySettings` method.
      Overrides:
        `setProxyHost` in class `Rexec`
      Parameters:
        `proxyHostname` - the hostname or ip address of the proxy server
        `proxyPort` - the port of the proxy server
      See Also:
        `clearProxySettings()`

    - #### setProxyType

          public void setProxyType(java.lang.String proxyType)

      Sets the proxy type will be used for this connection.
      Overrides:
        `setProxyType` in class `Rexec`
      Parameters:
        `proxyType` - The proxy type. Valid values: HTTP, SOCKS5

    - #### clearProxySettings

          public void clearProxySettings()

      Clears proxy server values.
      Overrides:
        `clearProxySettings` in class `Rexec`

Copyright © JSCAPE LLC. 1999-2021. All Rights Reserved