Java Doc for RCommandClient.java in  » Net » Apache-commons-net-1.4.1 » org » apache » commons » net » bsd » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » Apache commons net 1.4.1 » org.apache.commons.net.bsd 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


org.apache.commons.net.bsd.RExecClient
   org.apache.commons.net.bsd.RCommandClient

All known Subclasses:   org.apache.commons.net.bsd.RLoginClient,
RCommandClient
public class RCommandClient extends RExecClient (Code)
RCommandClient is very similar to org.apache.commons.net.bsd.RExecClient , from which it is derived, and implements the rcmd() facility that first appeared in 4.2BSD Unix. rcmd() is the facility used by the rsh (rshell) and other commands to execute a command on another machine from a trusted host without issuing a password. The trust relationship between two machines is established by the contents of a machine's /etc/hosts.equiv file and a user's .rhosts file. These files specify from which hosts and accounts on those hosts rcmd() requests will be accepted. The only additional measure for establishing trust is that all client connections must originate from a port between 512 and 1023. Consequently, there is an upper limit to the number of rcmd connections that can be running simultaneously. The required ports are reserved ports on Unix systems, and can only be bound by a process running with root permissions (to accomplish this rsh, rlogin, and related commands usualy have the suid bit set). Therefore, on a Unix system, you will only be able to successfully use the RCommandClient class if the process runs as root. However, there is no such restriction on Windows95 and some other systems. The security risks are obvious. However, when carefully used, rcmd() can be very useful when used behind a firewall.

As with virtually all of the client classes in org.apache.commons.net, this class derives from SocketClient. But it overrides most of its connection methods so that the local Socket will originate from an acceptable rshell port. The way to use RCommandClient is to first connect to the server, call the RCommandClient.rcommand rcommand() method, and then fetch the connection's input, output, and optionally error streams. Interaction with the remote command is controlled entirely through the I/O streams. Once you have finished processing the streams, you should invoke org.apache.commons.net.bsd.RExecClient.disconnect disconnect() to clean up properly.

By default the standard output and standard error streams of the remote process are transmitted over the same connection, readable from the input stream returned by org.apache.commons.net.bsd.RExecClient.getInputStream getInputStream() . However, it is possible to tell the rshd daemon to return the standard error stream over a separate connection, readable from the input stream returned by org.apache.commons.net.bsd.RExecClient.getErrorStream getErrorStream() . You can specify that a separate connection should be created for standard error by setting the boolean separateErrorStream parameter of RCommandClient.rcommand rcommand() to true . The standard input of the remote process can be written to through the output stream returned by org.apache.commons.net.bsd.RExecClient.getOutputStream getOutputStream() .


author:
   Daniel F. Savarese
See Also:   org.apache.commons.net.SocketClient
See Also:   RExecClient
See Also:   RLoginClient



Field Summary
final public static  intDEFAULT_PORT
     The default rshell port.
final public static  intMAX_CLIENT_PORT
     The largest port number an rcmd client may use.
final public static  intMIN_CLIENT_PORT
     The smallest port number an rcmd client may use.

Constructor Summary
public  RCommandClient()
     The default RCommandClient constructor.

Method Summary
 InputStream_createErrorStream()
    
public  voidconnect(InetAddress host, int port, InetAddress localAddr)
     Opens a Socket connected to a remote host at the specified port and originating from the specified local address using a port in a range acceptable to the BSD rshell daemon. Before returning, org.apache.commons.net.SocketClient._connectAction_ _connectAction_() is called to perform connection initialization actions.


Parameters:
  host - The remote host.
Parameters:
  port - The port to connect to on the remote host.
Parameters:
  localAddr - The local address to use.
exception:
  SocketException - If the socket timeout could not be set.
exception:
  BindException - If all acceptable rshell ports are in use.
exception:
  IOException - If the socket could not be opened.

public  voidconnect(InetAddress host, int port)
     Opens a Socket connected to a remote host at the specified port and originating from the current host at a port in a range acceptable to the BSD rshell daemon. Before returning, org.apache.commons.net.SocketClient._connectAction_ _connectAction_() is called to perform connection initialization actions.


Parameters:
  host - The remote host.
Parameters:
  port - The port to connect to on the remote host.
exception:
  SocketException - If the socket timeout could not be set.
exception:
  BindException - If all acceptable rshell ports are in use.
exception:
  IOException - If the socket could not be opened.

public  voidconnect(String hostname, int port)
     Opens a Socket connected to a remote host at the specified port and originating from the current host at a port in a range acceptable to the BSD rshell daemon. Before returning, org.apache.commons.net.SocketClient._connectAction_ _connectAction_() is called to perform connection initialization actions.


Parameters:
  hostname - The name of the remote host.
Parameters:
  port - The port to connect to on the remote host.
exception:
  SocketException - If the socket timeout could not be set.
exception:
  BindException - If all acceptable rshell ports are in use.
exception:
  IOException - If the socket could not be opened.

public  voidconnect(String hostname, int port, InetAddress localAddr)
     Opens a Socket connected to a remote host at the specified port and originating from the specified local address using a port in a range acceptable to the BSD rshell daemon. Before returning, org.apache.commons.net.SocketClient._connectAction_ _connectAction_() is called to perform connection initialization actions.


Parameters:
  hostname - The remote host.
Parameters:
  port - The port to connect to on the remote host.
Parameters:
  localAddr - The local address to use.
exception:
  SocketException - If the socket timeout could not be set.
exception:
  BindException - If all acceptable rshell ports are in use.
exception:
  IOException - If the socket could not be opened.

public  voidconnect(InetAddress host, int port, InetAddress localAddr, int localPort)
     Opens a Socket connected to a remote host at the specified port and originating from the specified local address and port.
public  voidconnect(String hostname, int port, InetAddress localAddr, int localPort)
     Opens a Socket connected to a remote host at the specified port and originating from the specified local address and port.
public  voidrcommand(String localUsername, String remoteUsername, String command, boolean separateErrorStream)
     Remotely executes a command through the rshd daemon on the server to which the RCommandClient is connected.
public  voidrcommand(String localUsername, String remoteUsername, String command)
    

Field Detail
DEFAULT_PORT
final public static int DEFAULT_PORT(Code)
The default rshell port. Set to 514 in BSD Unix.



MAX_CLIENT_PORT
final public static int MAX_CLIENT_PORT(Code)
The largest port number an rcmd client may use. By BSD convention this number is 1023.



MIN_CLIENT_PORT
final public static int MIN_CLIENT_PORT(Code)
The smallest port number an rcmd client may use. By BSD convention this number is 512.




Constructor Detail
RCommandClient
public RCommandClient()(Code)
The default RCommandClient constructor. Initializes the default port to DEFAULT_PORT .




Method Detail
_createErrorStream
InputStream _createErrorStream() throws IOException(Code)



connect
public void connect(InetAddress host, int port, InetAddress localAddr) throws SocketException, BindException, IOException(Code)
Opens a Socket connected to a remote host at the specified port and originating from the specified local address using a port in a range acceptable to the BSD rshell daemon. Before returning, org.apache.commons.net.SocketClient._connectAction_ _connectAction_() is called to perform connection initialization actions.


Parameters:
  host - The remote host.
Parameters:
  port - The port to connect to on the remote host.
Parameters:
  localAddr - The local address to use.
exception:
  SocketException - If the socket timeout could not be set.
exception:
  BindException - If all acceptable rshell ports are in use.
exception:
  IOException - If the socket could not be opened. In mostcases you will only want to catch IOException since SocketException isderived from it.




connect
public void connect(InetAddress host, int port) throws SocketException, IOException(Code)
Opens a Socket connected to a remote host at the specified port and originating from the current host at a port in a range acceptable to the BSD rshell daemon. Before returning, org.apache.commons.net.SocketClient._connectAction_ _connectAction_() is called to perform connection initialization actions.


Parameters:
  host - The remote host.
Parameters:
  port - The port to connect to on the remote host.
exception:
  SocketException - If the socket timeout could not be set.
exception:
  BindException - If all acceptable rshell ports are in use.
exception:
  IOException - If the socket could not be opened. In mostcases you will only want to catch IOException since SocketException isderived from it.




connect
public void connect(String hostname, int port) throws SocketException, IOException(Code)
Opens a Socket connected to a remote host at the specified port and originating from the current host at a port in a range acceptable to the BSD rshell daemon. Before returning, org.apache.commons.net.SocketClient._connectAction_ _connectAction_() is called to perform connection initialization actions.


Parameters:
  hostname - The name of the remote host.
Parameters:
  port - The port to connect to on the remote host.
exception:
  SocketException - If the socket timeout could not be set.
exception:
  BindException - If all acceptable rshell ports are in use.
exception:
  IOException - If the socket could not be opened. In mostcases you will only want to catch IOException since SocketException isderived from it.
exception:
  UnknownHostException - If the hostname cannot be resolved.




connect
public void connect(String hostname, int port, InetAddress localAddr) throws SocketException, IOException(Code)
Opens a Socket connected to a remote host at the specified port and originating from the specified local address using a port in a range acceptable to the BSD rshell daemon. Before returning, org.apache.commons.net.SocketClient._connectAction_ _connectAction_() is called to perform connection initialization actions.


Parameters:
  hostname - The remote host.
Parameters:
  port - The port to connect to on the remote host.
Parameters:
  localAddr - The local address to use.
exception:
  SocketException - If the socket timeout could not be set.
exception:
  BindException - If all acceptable rshell ports are in use.
exception:
  IOException - If the socket could not be opened. In mostcases you will only want to catch IOException since SocketException isderived from it.




connect
public void connect(InetAddress host, int port, InetAddress localAddr, int localPort) throws SocketException, IOException, IllegalArgumentException(Code)
Opens a Socket connected to a remote host at the specified port and originating from the specified local address and port. The local port must lie between MIN_CLIENT_PORT and MAX_CLIENT_PORT or an IllegalArgumentException will be thrown. Before returning, org.apache.commons.net.SocketClient._connectAction_ _connectAction_() is called to perform connection initialization actions.


Parameters:
  host - The remote host.
Parameters:
  port - The port to connect to on the remote host.
Parameters:
  localAddr - The local address to use.
Parameters:
  localPort - The local port to use.
exception:
  SocketException - If the socket timeout could not be set.
exception:
  IOException - If the socket could not be opened. In mostcases you will only want to catch IOException since SocketException isderived from it.
exception:
  IllegalArgumentException - If an invalid local port numberis specified.




connect
public void connect(String hostname, int port, InetAddress localAddr, int localPort) throws SocketException, IOException, IllegalArgumentException(Code)
Opens a Socket connected to a remote host at the specified port and originating from the specified local address and port. The local port must lie between MIN_CLIENT_PORT and MAX_CLIENT_PORT or an IllegalArgumentException will be thrown. Before returning, org.apache.commons.net.SocketClient._connectAction_ _connectAction_() is called to perform connection initialization actions.


Parameters:
  hostname - The name of the remote host.
Parameters:
  port - The port to connect to on the remote host.
Parameters:
  localAddr - The local address to use.
Parameters:
  localPort - The local port to use.
exception:
  SocketException - If the socket timeout could not be set.
exception:
  IOException - If the socket could not be opened. In mostcases you will only want to catch IOException since SocketException isderived from it.
exception:
  UnknownHostException - If the hostname cannot be resolved.
exception:
  IllegalArgumentException - If an invalid local port numberis specified.




rcommand
public void rcommand(String localUsername, String remoteUsername, String command, boolean separateErrorStream) throws IOException(Code)
Remotely executes a command through the rshd daemon on the server to which the RCommandClient is connected. After calling this method, you may interact with the remote process through its standard input, output, and error streams. You will typically be able to detect the termination of the remote process after reaching end of file on its standard output (accessible through RCommandClient.getInputStream getInputStream() . Disconnecting from the server or closing the process streams before reaching end of file will not necessarily terminate the remote process.

If a separate error stream is requested, the remote server will connect to a local socket opened by RCommandClient, providing an independent stream through which standard error will be transmitted. The local socket must originate from a secure port (512 - 1023), and rcommand() ensures that this will be so. RCommandClient will also do a simple security check when it accepts a connection for this error stream. If the connection does not originate from the remote server, an IOException will be thrown. This serves as a simple protection against possible hijacking of the error stream by an attacker monitoring the rexec() negotiation. You may disable this behavior with org.apache.commons.net.bsd.RExecClient.setRemoteVerificationEnabled setRemoteVerificationEnabled() .


Parameters:
  localUsername - The user account on the local machine that isrequesting the command execution.
Parameters:
  remoteUsername - The account name on the server through which toexecute the command.
Parameters:
  command - The command, including any arguments, to execute.
Parameters:
  separateErrorStream - True if you would like the standard errorto be transmitted through a different stream than standard output.False if not.
exception:
  IOException - If the rcommand() attempt fails. The exceptionwill contain a message indicating the nature of the failure.




rcommand
public void rcommand(String localUsername, String remoteUsername, String command) throws IOException(Code)
Same as rcommand(localUsername, remoteUsername, command, false);



Fields inherited from org.apache.commons.net.bsd.RExecClient
final public static int DEFAULT_PORT(Code)(Java Doc)
protected InputStream _errorStream_(Code)(Java Doc)

Methods inherited from org.apache.commons.net.bsd.RExecClient
InputStream _createErrorStream() throws IOException(Code)(Java Doc)
public void disconnect() throws IOException(Code)(Java Doc)
public InputStream getErrorStream()(Code)(Java Doc)
public InputStream getInputStream()(Code)(Java Doc)
public OutputStream getOutputStream()(Code)(Java Doc)
final public boolean isRemoteVerificationEnabled()(Code)(Java Doc)
public void rexec(String username, String password, String command, boolean separateErrorStream) throws IOException(Code)(Java Doc)
public void rexec(String username, String password, String command) throws IOException(Code)(Java Doc)
final public void setRemoteVerificationEnabled(boolean enable)(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.