com.jscape.inet.bsd

## Class Rexec

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

- All Implemented Interfaces:
    java.io.Serializable
  Direct Known Subclasses:
    Rlogin, Rsh

      public class Rexec
      extends java.lang.Object
      implements java.io.Serializable

  Implements the functionality of a BSD rexec client.

  Example Usage:

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

  See Also:
    Serialized Form

- - ### Constructor Summary

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

  - ### Method Summary

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

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

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

- - ### Constructor Detail

    - #### Rexec

          public Rexec(boolean hasErrorStream)

      Initializes the Rexec class with or without the error stream. That is, whether the stderr from remote host will be returned via dedicated connection - `Rexec(true)` or together with stdout - `Rexec(false)`. All other connection parameters are initialized to an empty `String`

      Parameters:
        `hasErrorStream` - If `true`, initialize separate error stream

    - #### Rexec

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

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

  - ### Method Detail

    - #### getInputStream

          public java.io.InputStream getInputStream()

      Returns the `InputStream` from which the standard output of the remote process can be read. The input stream will be set after `connect()` method invocation.

      Returns:
        `InputStream` from which the standard output of the remote process can be read. Until the `connect()` method has been invoked, `null` will be returned.

    - #### getOutputStream

          public java.io.OutputStream getOutputStream()

      Returns the `OutputStream` to which the standard input of the remote process can be written to. The output stream will be set after `connect()` method invocation.

      Returns:
        `OutputStream` from which the standard input of the remote process can be written. Until the `connect()` method has been invoked, `null` will be returned.

    - #### getErrorStream

          public 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. The error stream will only be set after a successful `execute()` invocation.

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

    - #### execute

          public void execute()
                       throws BsdException

      Executes command on the remote host. After calling this method, command is sent to remote host, and any response can be parsed using remote host's standard output. This output can be read through an `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()`
      Throws:
        `BsdException` - if the `execute()` fails.
      See Also:
        `getInputStream()`

    - #### connect

          public void connect()
                       throws BsdException

      Connects to the remote host, initializing streams that handle stdin and stdout.
      Throws:
        `BsdException` - if an error occurs while connecting.

    - #### disconnect

          public void disconnect()
                          throws BsdException

      Disconnects from the server, and cleans up all associated connections.
      Throws:
        `BsdException` - if an error occurs while disconnecting.

    - #### addBsdListener

          public void addBsdListener(BsdListener listener)

      Adds Bsd event listener.
      Parameters:
        `listener` - the listener to add
      See Also:
        `BsdListener`

    - #### removeBsdListener

          public void removeBsdListener(BsdListener listener)

      Removes specified Bsd event listener.
      Parameters:
        `listener` - the listener to remove
      See Also:
        `BsdListener`

    - #### getBsdListeners

          public java.util.Vector getBsdListeners()

      Gets all BsdListener currently bound to this `Rexec` instance.
      Returns:
        a `Vector` of `BsdListener`
      See Also:
        `BsdListener`

    - #### setRemoteHost

          public void setRemoteHost(java.lang.String remoteHost)

      Sets the name of the remote host to cennect to.
      Parameters:
        `remoteHost` - the remote host to connect to

    - #### getRemoteHost

          public java.lang.String getRemoteHost()

      Gets the name of the remote host.
      Returns:
        the remote host to connect to

    - #### setTimeout

          public void setTimeout(int timeout)

      Sets the timeout for opening connection to server.
      Parameters:
        `timeout` - the timeout in milliseconds

    - #### getTimeout

          public int getTimeout()

      Gets the timeout for opening connection to server.
      Returns:
        timeout in milliseconds

    - #### setPort

          public void setPort(int port)
                       throws BsdException

      Sets the port to be used to make the connection. TCP/IP restrictions apply - only valid port numbers are allowed. Otherwise, a `BsdException` is thrown.
      Parameters:
        `port` - the port to be used to make the connection.
      Throws:
        `BsdException` - if port is invalid

    - #### getPort

          public int getPort()

      Gets the port to be used to make the connection.
      Returns:
        the port used to make the connection.

    - #### setUsername

          public void setUsername(java.lang.String username)

      Sets the username to be sent to the remote host.
      Parameters:
        `username` - the username to be sent to the remote host.

    - #### getUsername

          public java.lang.String getUsername()

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

    - #### setPassword

          public void setPassword(java.lang.String password)

      Sets the password to be sent to the remote host.
      Parameters:
        `password` - the password to be sent to the remote host.

    - #### getPassword

          public java.lang.String getPassword()

      Gets the password to be sent to the remote host.
      Returns:
        the password to be sent to the remote host

    - #### setCommand

          public void setCommand(java.lang.String command)

      Sets the command to be sent to the remote host.
      Parameters:
        `command` - the command to be sent to the remote host.

    - #### getCommand

          public java.lang.String getCommand()

      Gets the command to be sent to the remote host.
      Returns:
        the command 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.
      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.
      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.
      Parameters:
        `proxyType` - The proxy type. Valid values: HTTP, SOCKS5

    - #### clearProxySettings

          public void clearProxySettings()

      Clears proxy server values.

    - #### hasErrorStream

          public boolean hasErrorStream()

      Returns weather the Rexec object was initialized with or without separate error stream.
      Returns:
        `true` if there is a separate error stream `false` otherwise

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