Package com.jcraft.jsch

Examples of com.jcraft.jsch.Channel


           
            // trying to connect ...
            session.connect();       
           
            String command="scp -p -t " + remoteName;
            final Channel channel = session.openChannel("exec");
            ((ChannelExec)channel).setCommand(command);       
           
            // get I/O streams for remote scp
            final OutputStream out=channel.getOutputStream();
            final InputStream in=channel.getInputStream();
           
            channel.connect();
           
            checkAck(in);
           
            // send "C0644 filesize filename", where filename should not include '/'
            final int filesize=(int)(localFile).length();
View Full Code Here


        }

        // exec 'scp -t -p hadoop.jar' remotely

        String command = "scp -p -t " + remoteFile;
        Channel channel = session.openChannel("exec");
        ((ChannelExec) channel).setCommand(command);

        // get I/O streams for remote scp
        OutputStream out = channel.getOutputStream();
        final InputStream in = channel.getInputStream();

        channel.connect();

        if (checkAck(in) != 0) {
          throw new CoreException(SSH_FAILED_STATUS1);
        }

        // send "C0644 filesize filename", where filename should not
        // include '/'
        long filesize = (new File(jarFile)).length();
        command = "C0644 " + filesize + " ";
        if (jarFile.lastIndexOf('/') > 0) {
          command += jarFile.substring(jarFile.lastIndexOf('/') + 1);
        } else {
          command += jarFile;
        }

        command += "\n";
        out.write(command.getBytes());
        out.flush();
        if (checkAck(in) != 0) {
          throw new CoreException(SSH_FAILED_STATUS2);
        }

        // send a content of jarFile
        fis = new FileInputStream(jarFile);
        byte[] buf = new byte[1024];
        while (true) {
          int len = fis.read(buf, 0, buf.length);
          if (len <= 0) {
            break;
          }
          out.write(buf, 0, len); // out.flush();
        }

        fis.close();
        fis = null;
        // send '\0'
        buf[0] = 0;
        out.write(buf, 0, 1);
        out.flush();
        if (checkAck(in) != 0) {
          throw new CoreException(SSH_FAILED_STATUS3);
        }
        out.close();
        channel.disconnect();

        // move the jar file to a temp directory
        String jarDir = "/tmp/hadoopjar"
            + new VMID().toString().replace(':', '_');
        command = "mkdir " + jarDir + ";mv " + remoteFile + " " + jarDir;
        channel = session.openChannel("exec");
        ((ChannelExec) channel).setCommand(command);
        channel.connect();
        channel.disconnect();

        session.disconnect();

        // we create a new session with a zero timeout to prevent the
        // console stream
View Full Code Here

          try {
            Session session = server.createSession();

            String command =
                server.getInstallPath() + "/bin/hadoop job -kill " + jobId;
            Channel channel = session.openChannel("exec");
            ((ChannelExec) channel).setCommand(command);
            channel.connect();
            channel.disconnect();

            session.disconnect();
          } catch (JSchException e) {
            e.printStackTrace();
          }
View Full Code Here

        JSchLogger.init();
        JSch sch = new JSch();
        com.jcraft.jsch.Session s = sch.getSession("smx", "localhost", port);
        s.setUserInfo(new SimpleUserInfo("smx"));
        s.connect();
        Channel c = s.openChannel("shell");
        c.connect();
        OutputStream os = c.getOutputStream();
        os.write("this is my command".getBytes());
        os.flush();
        Thread.sleep(100);
        c.disconnect();
        s.disconnect();
    }
View Full Code Here

        String command = "scp -f ";
        if (isRecursive) {
            command += "-r ";
        }
        command += remoteFile;
        Channel channel = openExecChannel(command);
        try {
            // get I/O streams for remote scp
            OutputStream out = channel.getOutputStream();
            InputStream in = channel.getInputStream();

            channel.connect();

            sendAck(out);
            startRemoteCpProtocol(in, out, localFile);
        } finally {
            if (channel != null) {
                channel.disconnect();
            }
        }
        log("done\n");
    }
View Full Code Here

        log("done.\n");
    }

    private void doSingleTransfer() throws IOException, JSchException {
        String cmd = "scp -t " + remotePath;
        Channel channel = openExecChannel(cmd);
        try {

            OutputStream out = channel.getOutputStream();
            InputStream in = channel.getInputStream();

            channel.connect();

            waitForAck(in);
            sendFileToRemote(localFile, in, out);
        } finally {
            if (channel != null) {
                channel.disconnect();
            }
        }
    }
View Full Code Here

            }
        }
    }

    private void doMultipleTransfer() throws IOException, JSchException {
        Channel channel = openExecChannel("scp -d -t " + remotePath);
        try {
            OutputStream out = channel.getOutputStream();
            InputStream in = channel.getInputStream();

            channel.connect();

            waitForAck(in);
            for (Iterator i = directoryList.iterator(); i.hasNext();) {
                Directory current = (Directory) i.next();
                sendDirectory(current, in, out);
            }
        } finally {
            if (channel != null) {
                channel.disconnect();
            }
        }
    }
View Full Code Here

        String command = "scp -f ";
        if (isRecursive) {
            command += "-r ";
        }
        command += remoteFile;
        Channel channel = openExecChannel(command);
        try {
            // get I/O streams for remote scp
            OutputStream out = channel.getOutputStream();
            InputStream in = channel.getInputStream();

            channel.connect();

            sendAck(out);
            startRemoteCpProtocol(in, out, localFile);
        } finally {
            if (channel != null) {
                channel.disconnect();
            }
        }
        log("done\n");
    }
View Full Code Here

  ChannelSftp newSftp() throws TransportException {
    final int tms = getTimeout() > 0 ? getTimeout() * 1000 : 0;
    try {
      // @TODO: Fix so that this operation is generic and casting to
      // JschSession is no longer necessary.
      final Channel channel = ((JschSession) getSession())
          .getSftpChannel();
      channel.connect(tms);
      return (ChannelSftp) channel;
    } catch (JSchException je) {
      throw new TransportException(uri, je.getMessage(), je);
    }
  }
View Full Code Here

      throws OpenShiftSSHOperationException {
    final Session session = getSSHSession();
    if (session == null) {
      throw new OpenShiftSSHOperationException("No SSH session available for application ''{0}''", this.getName());
    }
    Channel channel = null;
    BufferedReader reader = null;
    try {
      session.openChannel("exec");
      channel = session.openChannel("exec");
      ((ChannelExec) channel).setCommand(command);
      channel.connect();
      return sshStream.getLines(channel);
    } catch (JSchException e) {
      throw new OpenShiftSSHOperationException(e, "Failed to list forwardable ports for application \"{0}\"",
          this.getName());
    } catch (IOException e) {
      throw new OpenShiftSSHOperationException(e, "Failed to list forwardable ports for application \"{0}\"",
          this.getName());
    } finally {

      if (reader != null) {
        try {
          reader.close();
        } catch (IOException e) {
          LOGGER.error("Failed to close SSH error stream reader", e);
        }
      }

      if (channel != null && channel.isConnected()) {
        channel.disconnect();
      }
    }
  }
View Full Code Here

TOP

Related Classes of com.jcraft.jsch.Channel

Copyright © 2018 www.massapicom. 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.