Examples of RCommandClient


Examples of org.apache.commons.net.bsd.RCommandClient

{

    public static final void main(String[] args)
    {
        String server, localuser, remoteuser, command;
        RCommandClient client;

        if (args.length != 4)
        {
            System.err.println(
                "Usage: rshell <hostname> <localuser> <remoteuser> <command>");
            System.exit(1);
            return ; // so compiler can do proper flow control analysis
        }

        client = new RCommandClient();

        server = args[0];
        localuser = args[1];
        remoteuser = args[2];
        command = args[3];

        try
        {
            client.connect(server);
        }
        catch (IOException e)
        {
            System.err.println("Could not connect to server.");
            e.printStackTrace();
            System.exit(1);
        }

        try
        {
            client.rcommand(localuser, remoteuser, command);
        }
        catch (IOException e)
        {
            try
            {
                client.disconnect();
            }
            catch (IOException f)
            {}
            e.printStackTrace();
            System.err.println("Could not execute command.");
            System.exit(1);
        }


        IOUtil.readWrite(client.getInputStream(), client.getOutputStream(),
                         System.in, System.out);

        try
        {
            client.disconnect();
        }
        catch (IOException e)
        {
            e.printStackTrace();
            System.exit(1);
View Full Code Here

Examples of org.apache.commons.net.bsd.RCommandClient

   * @param fos
   *            data sink
   * @throws IOException
   */
  public void copyTo(final OutputStream fos) throws IOException {
    final RCommandClient rcmdClient = new RCommandClient();
    rcmdClient.connect(host);
    try {
      rcmdClient.rcommand(System.getProperty("user.name"), user,
          "rcp -f " + file);
      final InputStream is = rcmdClient.getInputStream();
      final OutputStream os = rcmdClient.getOutputStream();
      sendAck(os);
      // read server response header
      final ByteArrayOutputStream bos = new ByteArrayOutputStream();
      for (;;) {
        final int read = is.read();
        if (read < 0) {
          throw new EOFException("unexpected end of stream");
        }
        if (read == '\n') {
          break;
        }
        bos.write(read);
      }
      final String serverResponse = bos.toString("UTF-8");
      // expected header for regular file: C0644 <file-size> <filename>
      if (!serverResponse.isEmpty() && serverResponse.charAt(0) == 'C') {
        int start = 0;
        int end = serverResponse.indexOf(" ", start + 1);
        start = end + 1;
        end = serverResponse.indexOf(" ", start + 1);
        final long filesize = Long.parseLong(serverResponse.substring(
            start, end));
        sendAck(os);
        copyStream(is, fos, filesize);
        expectAck(is);
        sendAck(os);
      } else {
        throw new FileNotFoundException("unexpected server response: "
            + serverResponse.trim());
      }
    } finally {
      rcmdClient.disconnect();
    }
  }
View Full Code Here

Examples of org.apache.commons.net.bsd.RCommandClient

   *            number of bytes to be read from the input stream
   * @throws IOException
   */
  public void copyFrom(final InputStream fis, final long filesize)
      throws IOException {
    final RCommandClient rcmdClient = new RCommandClient();
    rcmdClient.connect(host);
    try {
      rcmdClient.rcommand(System.getProperty("user.name"), user,
          "rcp -t " + file);
      final InputStream is = rcmdClient.getInputStream();
      final OutputStream os = rcmdClient.getOutputStream();
      expectAck(is);
      final String header = "C0644 " + filesize + " "
          + new File(file).getName() + "\n";
      os.write(header.getBytes("UTF-8"));
      expectAck(is);
      copyStream(fis, os, filesize);
      sendAck(os);
      expectAck(is);
    } finally {
      rcmdClient.disconnect();
    }
  }
View Full Code Here

Examples of org.apache.commons.net.bsd.RCommandClient

{

    public static final void main(String[] args)
    {
        String server, localuser, remoteuser, command;
        RCommandClient client;

        if (args.length != 4)
        {
            System.err.println(
                "Usage: rshell <hostname> <localuser> <remoteuser> <command>");
            System.exit(1);
            return ; // so compiler can do proper flow control analysis
        }

        client = new RCommandClient();

        server = args[0];
        localuser = args[1];
        remoteuser = args[2];
        command = args[3];

        try
        {
            client.connect(server);
        }
        catch (IOException e)
        {
            System.err.println("Could not connect to server.");
            e.printStackTrace();
            System.exit(1);
        }

        try
        {
            client.rcommand(localuser, remoteuser, command);
        }
        catch (IOException e)
        {
            try
            {
                client.disconnect();
            }
            catch (IOException f)
            {}
            e.printStackTrace();
            System.err.println("Could not execute command.");
            System.exit(1);
        }


        IOUtil.readWrite(client.getInputStream(), client.getOutputStream(),
                         System.in, System.out);

        try
        {
            client.disconnect();
        }
        catch (IOException e)
        {
            e.printStackTrace();
            System.exit(1);
View Full Code Here

Examples of org.apache.commons.net.bsd.RCommandClient

{

    public static final void main(String[] args)
    {
        String server, localuser, remoteuser, command;
        RCommandClient client;

        if (args.length != 4)
        {
            System.err.println(
                "Usage: rshell <hostname> <localuser> <remoteuser> <command>");
            System.exit(1);
            return ; // so compiler can do proper flow control analysis
        }

        client = new RCommandClient();

        server = args[0];
        localuser = args[1];
        remoteuser = args[2];
        command = args[3];

        try
        {
            client.connect(server);
        }
        catch (IOException e)
        {
            System.err.println("Could not connect to server.");
            e.printStackTrace();
            System.exit(1);
        }

        try
        {
            client.rcommand(localuser, remoteuser, command);
        }
        catch (IOException e)
        {
            try
            {
                client.disconnect();
            }
            catch (IOException f)
            {}
            e.printStackTrace();
            System.err.println("Could not execute command.");
            System.exit(1);
        }


        IOUtil.readWrite(client.getInputStream(), client.getOutputStream(),
                         System.in, System.out);

        try
        {
            client.disconnect();
        }
        catch (IOException e)
        {
            e.printStackTrace();
            System.exit(1);
View Full Code Here

Examples of org.apache.commons.net.bsd.RCommandClient

{

    public static final void main(String[] args)
    {
        String server, localuser, remoteuser, command;
        RCommandClient client;

        if (args.length != 4)
        {
            System.err.println(
                "Usage: rshell <hostname> <localuser> <remoteuser> <command>");
            System.exit(1);
            return ; // so compiler can do proper flow control analysis
        }

        client = new RCommandClient();

        server = args[0];
        localuser = args[1];
        remoteuser = args[2];
        command = args[3];

        try
        {
            client.connect(server);
        }
        catch (IOException e)
        {
            System.err.println("Could not connect to server.");
            e.printStackTrace();
            System.exit(1);
        }

        try
        {
            client.rcommand(localuser, remoteuser, command);
        }
        catch (IOException e)
        {
            try
            {
                client.disconnect();
            }
            catch (IOException f)
            {}
            e.printStackTrace();
            System.err.println("Could not execute command.");
            System.exit(1);
        }


        IOUtil.readWrite(client.getInputStream(), client.getOutputStream(),
                         System.in, System.out);

        try
        {
            client.disconnect();
        }
        catch (IOException e)
        {
            e.printStackTrace();
            System.exit(1);
View Full Code Here

Examples of org.apache.commons.net.bsd.RCommandClient

{

    public static final void main(String[] args)
    {
        String server, localuser, remoteuser, command;
        RCommandClient client;

        if (args.length != 4)
        {
            System.err.println(
                "Usage: rshell <hostname> <localuser> <remoteuser> <command>");
            System.exit(1);
            return ; // so compiler can do proper flow control analysis
        }

        client = new RCommandClient();

        server = args[0];
        localuser = args[1];
        remoteuser = args[2];
        command = args[3];

        try
        {
            client.connect(server);
        }
        catch (IOException e)
        {
            System.err.println("Could not connect to server.");
            e.printStackTrace();
            System.exit(1);
        }

        try
        {
            client.rcommand(localuser, remoteuser, command);
        }
        catch (IOException e)
        {
            try
            {
                client.disconnect();
            }
            catch (IOException f)
            {}
            e.printStackTrace();
            System.err.println("Could not execute command.");
            System.exit(1);
        }


        IOUtil.readWrite(client.getInputStream(), client.getOutputStream(),
                         System.in, System.out);

        try
        {
            client.disconnect();
        }
        catch (IOException e)
        {
            e.printStackTrace();
            System.exit(1);
View Full Code Here

Examples of org.apache.commons.net.bsd.RCommandClient

{

    public static void main(String[] args)
    {
        String server, localuser, remoteuser, command;
        RCommandClient client;

        if (args.length != 4)
        {
            System.err.println(
                "Usage: rshell <hostname> <localuser> <remoteuser> <command>");
            System.exit(1);
            return ; // so compiler can do proper flow control analysis
        }

        client = new RCommandClient();

        server = args[0];
        localuser = args[1];
        remoteuser = args[2];
        command = args[3];

        try
        {
            client.connect(server);
        }
        catch (IOException e)
        {
            System.err.println("Could not connect to server.");
            e.printStackTrace();
            System.exit(1);
        }

        try
        {
            client.rcommand(localuser, remoteuser, command);
        }
        catch (IOException e)
        {
            try
            {
                client.disconnect();
            }
            catch (IOException f)
            {}
            e.printStackTrace();
            System.err.println("Could not execute command.");
            System.exit(1);
        }


        IOUtil.readWrite(client.getInputStream(), client.getOutputStream(),
                         System.in, System.out);

        try
        {
            client.disconnect();
        }
        catch (IOException e)
        {
            e.printStackTrace();
            System.exit(1);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.