/*** * 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. * * @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. * @throws SocketException If the socket timeout could not be set. * @throws IOException If the socket could not be opened. In most * cases you will only want to catch IOException since SocketException is * derived from it. * @throws IllegalArgumentException If an invalid local port number * is specified. ***/ @Override 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); }
/*** * Same as <code> rexec(username, password, command, false); </code> * @param username the user name * @param password the password * @param command the command to run * @throws IOException if an error occurs ***/ public void rexec(String username, String password, String command) throws IOException { rexec(username, password, command, false); }
_errorStream_ = _createErrorStream(); _output_.write(username.getBytes(getCharset())); _output_.write(NULL_CHAR); _output_.write(password.getBytes(getCharset())); _output_.write(NULL_CHAR); _output_.write(command.getBytes(getCharset())); _output_.write(NULL_CHAR); _output_.flush();
InputStream _createErrorStream() throws IOException { ServerSocket server; Socket socket; server = _serverSocketFactory_.createServerSocket(0, 1, getLocalAddress()); _output_.write(Integer.toString(server.getLocalPort()).getBytes("UTF-8")); // $NON-NLS-1$ _output_.write(NULL_CHAR); _output_.flush(); socket = server.accept(); server.close(); if (__remoteVerificationEnabled && !verifyRemote(socket)) { socket.close(); throw new IOException( "Security violation: unexpected connection attempt by " + socket.getInetAddress().getHostAddress()); } return (new SocketInputStream(socket, socket.getInputStream())); }
client = new RExecClient(); if (client != null) { try { if (!client.isConnected()) { client.connect(url); client.rexec(login, password, cmd); is = client.getInputStream(); if (is != null && is.available() > 0) { res = IOUtils.toString(is); client.disconnect();
/*** * The default RExecClient constructor. Initializes the * default port to <code> DEFAULT_PORT </code>. ***/ public RExecClient() { _errorStream_ = null; setDefaultPort(DEFAULT_PORT); }
_errorStream_ = _createErrorStream();
InputStream _createErrorStream() throws IOException { ServerSocket server; Socket socket; server = _serverSocketFactory_.createServerSocket(0, 1, getLocalAddress()); _output_.write(Integer.toString(server.getLocalPort()).getBytes()); _output_.write('\0'); _output_.flush(); socket = server.accept(); server.close(); if (__remoteVerificationEnabled && !verifyRemote(socket)) { socket.close(); throw new IOException( "Security violation: unexpected connection attempt by " + socket.getInetAddress().getHostAddress()); } return (new SocketInputStream(socket, socket.getInputStream())); }
/*** * The default RExecClient constructor. Initializes the * default port to <code> DEFAULT_PORT </code>. ***/ public RExecClient() { _errorStream_ = null; setDefaultPort(DEFAULT_PORT); }
_errorStream_ = _createErrorStream();
InputStream _createErrorStream() throws IOException { ServerSocket server; Socket socket; server = _socketFactory_.createServerSocket(0, 1, getLocalAddress()); _output_.write(Integer.toString(server.getLocalPort()).getBytes()); _output_.write('\0'); _output_.flush(); socket = server.accept(); server.close(); if (__remoteVerificationEnabled && !verifyRemote(socket)) { socket.close(); throw new IOException( "Security violation: unexpected connection attempt by " + socket.getInetAddress().getHostAddress()); } return (new SocketInputStream(socket, socket.getInputStream())); }
throw new IllegalArgumentException("Invalid port number " + localPort); super.connect(hostname, port, localAddr, localPort);
/*** * Same as <code> rexec(username, password, command, false); </code> ***/ public void rexec(String username, String password, String command) throws IOException { rexec(username, password, command, false); }
/*** * The default RExecClient constructor. Initializes the * default port to <code> DEFAULT_PORT </code>. ***/ public RExecClient() { _errorStream_ = null; setDefaultPort(DEFAULT_PORT); }
/*** * 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); }
/*** * Same as <code> rexec(username, password, command, false); </code> ***/ public void rexec(String username, String password, String command) throws IOException { rexec(username, password, command, false); }
/*** * 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. ***/ @Override 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); }
/*** * 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. ***/ @Override 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); }