|
IP*Works! V8 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--ipworks.Rexec
The Rexec bean is used to execute commands on a remote UNIX machine using the rexec mechanism.
The Rexec bean allows remote execution of commands on UNIX hosts,
or any other system with the rexec interface. Using the bean
is very simple. The destination is specified by the RemoteHost property, the login information is given by the RemoteUser and RemotePassword properties. Then call the Execute method with the Command to execute as a parameter. You can also set the Command property to the command that you would like to execute for identical
results. Further input can be supplied to the command by assigning data
to the Text parameter of the Send method, or via the Stdin property.
The output of the command is returned through the Stdout event. If an error happens on the protocol
level, the error message can be found in the ErrorMessage property. Errors
during command execution (the stderr stream) are given by the Stderr event.
To be able to successfully use the bean, the remote host must be set up to allow execution of commands via rexec from the machine the bean runs on.
| Constructor Summary | |
Rexec()
|
|
| Method Summary | |
void |
addRexecEventListener(ipworks.RexecEventListener l)
|
java.lang.String |
config(java.lang.String configurationString)
Sets or retrieves a beanconfiguration setting. |
void |
disconnect()
Disconnect from the RemoteHost . |
void |
doEvents()
Processes events from the internal message queue. |
void |
execute(java.lang.String command)
Execute a Command on the remote host. |
int |
getBytesSent()
The number of bytes actually sent after an assignment to Stdin. |
java.lang.String |
getCommand()
The command to be sent to the remote host. |
byte[] |
getEOL()
Used to break the stdout data stream into chunks separated by its value. |
byte[] |
getErrEOL()
Used to break the stderr data stream into chunks separated by its value. |
java.lang.String |
getErrorMessage()
The error message returned when any of the steps prior to command execution fail. |
ipworks.Firewall |
getFirewall()
A set of properties related to firewall access. |
java.lang.String |
getLocalHost()
The name of the local host or user-assigned IP interface through which connections are initiated or accepted. |
int |
getLocalPort()
The TCP port in the local host where the bean binds. |
java.lang.String |
getRemoteHost()
The address of the remote host. |
java.lang.String |
getRemotePassword()
The password of the user on the remote host. |
int |
getRemotePort()
The remote exec service port (default is 512). |
java.lang.String |
getRemoteUser()
The id of the user on the remote host. |
byte[] |
getStderr()
Returns the standard error output (stderr) from the remote application. |
byte[] |
getStdout()
Provides the standard output (stdout) from the remote application. |
int |
getTimeout()
A timeout for the bean. |
void |
interrupt()
Interrupt the current method. |
boolean |
isConnected()
Shows whether the bean is connected. |
boolean |
isEOF()
If True, the connection has closed, and there is no buffered data available. |
void |
removeRexecEventListener(ipworks.RexecEventListener l)
|
void |
send(byte[] text)
Execute a Command on the remote host. |
void |
setCommand(java.lang.String command)
The command to be sent to the remote host. |
void |
setConnected(boolean connected)
Shows whether the bean is connected. |
void |
setEOL(byte[] EOL)
Used to break the stdout data stream into chunks separated by its value. |
void |
setErrEOL(byte[] errEOL)
Used to break the stderr data stream into chunks separated by its value. |
void |
setFirewall(ipworks.Firewall firewall)
A set of properties related to firewall access. |
void |
setLocalHost(java.lang.String localHost)
The name of the local host or user-assigned IP interface through which connections are initiated or accepted. |
void |
setLocalPort(int localPort)
The TCP port in the local host where the bean binds. |
void |
setRemoteHost(java.lang.String remoteHost)
The address of the remote host. |
void |
setRemotePassword(java.lang.String remotePassword)
The password of the user on the remote host. |
void |
setRemotePort(int remotePort)
The remote exec service port (default is 512). |
void |
setRemoteUser(java.lang.String remoteUser)
The id of the user on the remote host. |
void |
setStdin(byte[] stdin)
A string of data to be sent to the remote host while connected. |
void |
setTimeout(int timeout)
A timeout for the bean. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public Rexec()
| Method Detail |
public int getBytesSent()
The BytesSent property shows how many bytes were sent after the last
assignment to Stdin . Please check the Stdin property for more
information.
public java.lang.String getCommand()
Assigning a UNIX command to this property makes the bean
attempt to connect to the RemoteHost and execute
the command using the rexec protocol. There is no need
to append an end-of-line character to the command.
If "" (empty string) is assigned to the Command property,
the current connection is broken.
Example (Execute a Command)
RexecControl.Command = "cd /home/username/; ls -al; cd/; ls"
public void setCommand(java.lang.String command)
throws IPWorksException
Assigning a UNIX command to this property makes the bean
attempt to connect to the RemoteHost and execute
the command using the rexec protocol. There is no need
to append an end-of-line character to the command.
If "" (empty string) is assigned to the Command property,
the current connection is broken.
Example (Execute a Command)
RexecControl.Command = "cd /home/username/; ls -al; cd/; ls"
IPWorksExceptionpublic boolean isConnected()
Use this property to determine whether the bean is connected to the remote host or not.
public void setConnected(boolean connected)
throws IPWorksException
Use this property to determine whether the bean is connected to the remote host or not.
IPWorksExceptionpublic boolean isEOF()
EOF is an acronym for "End Of File".
public byte[] getEOL()
The EOL property is used to define boundaries in the Stdout
stream using the value of the property.
public void setEOL(byte[] EOL)
throws IPWorksException
The EOL property is used to define boundaries in the Stdout
stream using the value of the property.
IPWorksExceptionpublic byte[] getErrEOL()
The ErrEOL property is used to define boundaries in the Stderr
stream using the value of the property.
public void setErrEOL(byte[] errEOL)
throws IPWorksException
The ErrEOL property is used to define boundaries in the Stderr
stream using the value of the property.
IPWorksExceptionpublic java.lang.String getErrorMessage()
This error message is returned on a separate connection associated with error messages.
public ipworks.Firewall getFirewall()
This is a FIREWALL type property which
contains fields describing the firewall
through which the bean will attempt to connect.
public void setFirewall(ipworks.Firewall firewall)
throws IPWorksException
This is a FIREWALL type property which
contains fields describing the firewall
through which the bean will attempt to connect.
IPWorksExceptionpublic java.lang.String getLocalHost()
The LocalHost property contains the name of the local host
as obtained by the gethostname() system call, or if the
user has assigned an IP address, the value of that address.
In multihomed hosts (machines with more than one IP interface) setting LocalHost to the value of an interface will make the bean initiate connections (or accept in the case of server beans) only through that interface.
If the bean is connected, the LocalHost property shows
the IP address of the interface through which the connection
is made in internet dotted format (aaa.bbb.ccc.ddd). In most
cases, this is the address of the local host, except for multihomed
hosts (machines with more than one IP interface).
NOTE: LocalHost is not persistent. You must always set it in
code, and never in the property window.
public void setLocalHost(java.lang.String localHost)
throws IPWorksException
The LocalHost property contains the name of the local host
as obtained by the gethostname() system call, or if the
user has assigned an IP address, the value of that address.
In multihomed hosts (machines with more than one IP interface) setting LocalHost to the value of an interface will make the bean initiate connections (or accept in the case of server beans) only through that interface.
If the bean is connected, the LocalHost property shows
the IP address of the interface through which the connection
is made in internet dotted format (aaa.bbb.ccc.ddd). In most
cases, this is the address of the local host, except for multihomed
hosts (machines with more than one IP interface).
NOTE: LocalHost is not persistent. You must always set it in
code, and never in the property window.
IPWorksExceptionpublic int getLocalPort()
The LocalPort property must be set before a connection is
attempted. It instructs the bean to bind to a specific
port (or communication endpoint) in the local machine.
Setting it to 0 (default) enables the bean to choose a port
at random. The chosen port will be shown by the LocalPort property after the connection is established.
LocalPort cannot be changed once a connection is made.
Any attempt to set the LocalPort property when a connection
is active will generate an error.
Use this property with caution. If you supply a value,
it must be an available port on the system, or an error will be
returned. Furthermore, the bean always attempts to bind to
a secure (sub 1000) port when the value of LocalPort is the
default (0). If you supply your own value, make sure the remote
system is configured to allow that particular value.
public void setLocalPort(int localPort)
throws IPWorksException
The LocalPort property must be set before a connection is
attempted. It instructs the bean to bind to a specific
port (or communication endpoint) in the local machine.
Setting it to 0 (default) enables the bean to choose a port
at random. The chosen port will be shown by the LocalPort property after the connection is established.
LocalPort cannot be changed once a connection is made.
Any attempt to set the LocalPort property when a connection
is active will generate an error.
Use this property with caution. If you supply a value,
it must be an available port on the system, or an error will be
returned. Furthermore, the bean always attempts to bind to
a secure (sub 1000) port when the value of LocalPort is the
default (0). If you supply your own value, make sure the remote
system is configured to allow that particular value.
IPWorksExceptionpublic java.lang.String getRemoteHost()
The RemoteHost property specifies the IP address (IP number in
dotted internet format) or Domain Name of the remote host.
It is set before a connection is attempted and cannot be changed
once a connection is established.
If the RemoteHost property is set to a Domain Name, a DNS request
is initiated, and upon successful termination of the request, the RemoteHost property is set to the corresponding address. If the
search is not successful, an error is returned.
If the bean is configured to use a SOCKS firewall, the value assigned to this property may be preceeded with a "*". If this is the case, the host name is passed to the firewall unresolved and the firewall performs the DNS resolution.
Example (Connecting)
IPPortControl.RemoteHost = "MyHostNameOrIP"
IPPortControl.RemotePort = 777
IPPortControl.Connected = true
public void setRemoteHost(java.lang.String remoteHost)
throws IPWorksException
The RemoteHost property specifies the IP address (IP number in
dotted internet format) or Domain Name of the remote host.
It is set before a connection is attempted and cannot be changed
once a connection is established.
If the RemoteHost property is set to a Domain Name, a DNS request
is initiated, and upon successful termination of the request, the RemoteHost property is set to the corresponding address. If the
search is not successful, an error is returned.
If the bean is configured to use a SOCKS firewall, the value assigned to this property may be preceeded with a "*". If this is the case, the host name is passed to the firewall unresolved and the firewall performs the DNS resolution.
Example (Connecting)
IPPortControl.RemoteHost = "MyHostNameOrIP"
IPPortControl.RemotePort = 777
IPPortControl.Connected = true
IPWorksExceptionpublic java.lang.String getRemotePassword()
This must be the password of a user in the remote host for whom remote execution of commands is permitted.
public void setRemotePassword(java.lang.String remotePassword)
throws IPWorksException
This must be the password of a user in the remote host for whom remote execution of commands is permitted.
IPWorksExceptionpublic int getRemotePort()
The RemotePort property specifies the rexec service port on the
remote host.
A valid port number (a value between 1 and 65535) is required for the connection to take place. The property must be set before command execution is attempted.
public void setRemotePort(int remotePort)
throws IPWorksException
The RemotePort property specifies the rexec service port on the
remote host.
A valid port number (a value between 1 and 65535) is required for the connection to take place. The property must be set before command execution is attempted.
IPWorksExceptionpublic java.lang.String getRemoteUser()
This must be the id of a user in the remote host for whom remote execution of commands is permitted.
public void setRemoteUser(java.lang.String remoteUser)
throws IPWorksException
This must be the id of a user in the remote host for whom remote execution of commands is permitted.
IPWorksExceptionpublic byte[] getStderr()
The property is set to an empty string before each new request.
public void setStdin(byte[] stdin)
throws IPWorksException
This property is used to provide input for the process in the remote host.
If you are sending data to the remote host faster than it can
process it, or faster than the network bandwidth allows, the outgoing
queue might fill up. When this happens, Stdin fails with exception 10035: "[10035] Operation would block" (WSAEWOULDBLOCK).
You can check this error, and then try to send the data again.
IPWorksExceptionpublic byte[] getStdout()
The property is set to an empty string before each new request.
public int getTimeout()
If the Timeout property is set to 0, all operations return
immediately, potentially failing with an error if they can't be
completed immediately.
If Timeout is set to a positive value, the bean will
wait for the operation to complete before returning control.
The bean will use DoEvents to enter an efficient wait loop
during any potential waiting period, making sure that all system events
are processed immediately as they arrive. This ensures that the host
application does not "freeze" and remains responsive.
If Timeout expires, and the operation is not yet complete,
the bean throws an IPWorksException
raises an IPWorksException exception
.
Please note that by default, all timeouts are inactivity timeouts ,
i.e. the timeout period is extended by Timeout seconds when
data is successfully sent or received.
Optionally, the behaviour of the bean may be changed to absolute timeouts , i.e. the bean will wait for a maximum
of Timeout seconds since the beginning of the operation, without
extending the timeout period during communications.
This behavior is controlled by theAbsoluteTimeoutconfiguration setting.
The default value for the Timeout property is 60 seconds.
public void setTimeout(int timeout)
throws IPWorksException
If the Timeout property is set to 0, all operations return
immediately, potentially failing with an error if they can't be
completed immediately.
If Timeout is set to a positive value, the bean will
wait for the operation to complete before returning control.
The bean will use DoEvents to enter an efficient wait loop
during any potential waiting period, making sure that all system events
are processed immediately as they arrive. This ensures that the host
application does not "freeze" and remains responsive.
If Timeout expires, and the operation is not yet complete,
the bean throws an IPWorksException
raises an IPWorksException exception
.
Please note that by default, all timeouts are inactivity timeouts ,
i.e. the timeout period is extended by Timeout seconds when
data is successfully sent or received.
Optionally, the behaviour of the bean may be changed to absolute timeouts , i.e. the bean will wait for a maximum
of Timeout seconds since the beginning of the operation, without
extending the timeout period during communications.
This behavior is controlled by theAbsoluteTimeoutconfiguration setting.
The default value for the Timeout property is 60 seconds.
IPWorksException
public java.lang.String config(java.lang.String configurationString)
throws IPWorksException
Config is a generic method available in every bean.
It is used to set and retrieveconfiguration settingsfor the
bean.
Configuration settings are similar in functionality to properties,
but they are rarely used. In order to avoid "polluting" the property
namespace of the bean, access to these internal properties is provided through the Config method.
To set a configuration setting named PROPERTY , you must call Config("PROPERTY=VALUE") , where VALUE is the value of the setting expressed as a string. For boolean values, use the strings "True", "False", "0", "1", "Yes", or "No" (case does not matter).
To read (query) the value of a configuration setting, you must call Config("PROPERTY") . The value will be returned as a string.
IPWorksException
public void disconnect()
throws IPWorksException
RemoteHost .
Calling this method is normally unneccessary, unless you wish to interrupt the remote program, or the remote program is waiting for standard input to end before terminating.
IPWorksException
public void doEvents()
throws IPWorksException
When DoEvents is called, the bean processes any
available events. If no events are available, it waits for a
preset period of time, and then returns.
IPWorksException
public void execute(java.lang.String command)
throws IPWorksException
Command on the remote host.
Calling this method is equivalent to setting the Command property
to Command .
Example (Execute a Command)
RexecControl.Execute("cd /home/username/; ls -al; cd/; ls")
IPWorksException
public void interrupt()
throws IPWorksException
If there is no method in progress, Interrupt simply returns doing nothing.
IPWorksException
public void send(byte[] text)
throws IPWorksException
Command on the remote host.
The bean attempts to connect to the RemoteHost and execute
the Command using the rexec protocol. There is no need to append
an end-of-line character to the command.
IPWorksException
public void addRexecEventListener(ipworks.RexecEventListener l)
throws java.util.TooManyListenersException
java.util.TooManyListenersExceptionpublic void removeRexecEventListener(ipworks.RexecEventListener l)
|
IP*Works! V8 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||