rcommandclient.java

来自「apache推出的net包」· Java 代码 · 共 393 行 · 第 1/2 页

JAVA
393
字号
        if (localPort < MIN_CLIENT_PORT)            throw new BindException("All ports in use or insufficient permssion.");        _connectAction_();    }    /***     * 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, {@link org.apache.commons.net.SocketClient#_connectAction_  _connectAction_() }     * is called to perform connection initialization actions.     * <p>     * @param host  The remote host.     * @param 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 most     *  cases you will only want to catch IOException since SocketException is     *  derived from it.     ***/    public void connect(InetAddress host, int port)    throws SocketException, IOException    {        connect(host, port, InetAddress.getLocalHost());    }    /***     * 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, {@link org.apache.commons.net.SocketClient#_connectAction_  _connectAction_() }     * is called to perform connection initialization actions.     * <p>     * @param hostname  The name of the remote host.     * @param 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 most     *  cases you will only want to catch IOException since SocketException is     *  derived from it.     * @exception UnknownHostException If the hostname cannot be resolved.     ***/    public void connect(String hostname, int port)    throws SocketException, IOException    {        connect(InetAddress.getByName(hostname), port, InetAddress.getLocalHost());    }    /***     * 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, {@link org.apache.commons.net.SocketClient#_connectAction_  _connectAction_() }     * is called to perform connection initialization actions.     * <p>     * @param hostname  The remote host.     * @param port  The port to connect to on the remote host.     * @param 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 most     *  cases you will only want to catch IOException since SocketException is     *  derived from it.     ***/    public void connect(String hostname, int port, InetAddress localAddr)    throws SocketException, IOException    {        connect(InetAddress.getByName(hostname), port, localAddr);    }    /***     * 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 <code> MIN_CLIENT_PORT </code> and     * <code> MAX_CLIENT_PORT </code> or an IllegalArgumentException will     * be thrown.     * Before returning, {@link org.apache.commons.net.SocketClient#_connectAction_  _connectAction_() }     * is called to perform connection initialization actions.     * <p>     * @param host  The remote host.     * @param port  The port to connect to on the remote host.     * @param localAddr  The local address to use.     * @param 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 most     *  cases you will only want to catch IOException since SocketException is     *  derived from it.     * @exception IllegalArgumentException If an invalid local port number     *            is specified.     ***/    public void connect(InetAddress host, int port,                        InetAddress localAddr, int localPort)    throws SocketException, IOException, IllegalArgumentException    {        if (localPort < MIN_CLIENT_PORT || localPort > MAX_CLIENT_PORT)            throw new IllegalArgumentException("Invalid port number " + localPort);        super.connect(host, port, localAddr, localPort);    }    /***     * 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 <code> MIN_CLIENT_PORT </code> and     * <code> MAX_CLIENT_PORT </code> or an IllegalArgumentException will     * be thrown.     * Before returning, {@link org.apache.commons.net.SocketClient#_connectAction_  _connectAction_() }     * is called to perform connection initialization actions.     * <p>     * @param hostname  The name of the remote host.     * @param port  The port to connect to on the remote host.     * @param localAddr  The local address to use.     * @param 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 most     *  cases you will only want to catch IOException since SocketException is     *  derived from it.     * @exception UnknownHostException If the hostname cannot be resolved.     * @exception IllegalArgumentException If an invalid local port number     *            is specified.     ***/    public void connect(String hostname, int port,                        InetAddress localAddr, int localPort)    throws SocketException, IOException, IllegalArgumentException    {        if (localPort < MIN_CLIENT_PORT || localPort > MAX_CLIENT_PORT)            throw new IllegalArgumentException("Invalid port number " + localPort);        super.connect(hostname, port, localAddr, localPort);    }    /***     * 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     * {@link #getInputStream  getInputStream() }.  Disconnecting     * from the server or closing the process streams before reaching     * end of file will not necessarily terminate the remote process.     * <p>     * 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     * {@link org.apache.commons.net.bsd.RExecClient#setRemoteVerificationEnabled setRemoteVerificationEnabled()}     * .     * <p>     * @param localUsername  The user account on the local machine that is     *        requesting the command execution.     * @param remoteUsername  The account name on the server through which to     *        execute the command.     * @param command   The command, including any arguments, to execute.     * @param separateErrorStream True if you would like the standard error     *        to be transmitted through a different stream than standard output.     *        False if not.     * @exception IOException If the rcommand() attempt fails.  The exception     *            will contain a message indicating the nature of the failure.     ***/    public void rcommand(String localUsername, String remoteUsername,                         String command, boolean separateErrorStream)    throws IOException    {        rexec(localUsername, remoteUsername, command, separateErrorStream);    }    /***     * Same as     * <code> rcommand(localUsername, remoteUsername, command, false); </code>     ***/    public void rcommand(String localUsername, String remoteUsername,                         String command)    throws IOException    {        rcommand(localUsername, remoteUsername, command, false);    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?