Package com.jcraft.jsch

Examples of com.jcraft.jsch.Channel


  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


  ScpUploadChannel build() {
    try {
      String flags = getFlags();
      String command = String.format("scp %s %s", flags, dest);
      Channel channel = session.openChannel("exec");
      ((ChannelExec) channel).setCommand(command);
      return successInstance(channel, src);

    } catch (JSchException e) {
      return new ScpUploadChannelFailed(e);
View Full Code Here

    @SuppressWarnings("resource")
    public boolean execSyncCommand(String command, PrintStream stdoutConsumer, PrintStream stderrConsumer) throws JSchException, IOException {
  InputStream stdout = null;
  InputStream stderr = null;
  Channel channel = null;
  try {
      channel = session.openChannel("exec");
      ((ChannelExec) channel).setCommand(command);

      channel.setInputStream(null);

      stdout = channel.getInputStream();
      stderr = ((ChannelExec) channel).getErrStream();

      channel.connect();

      int exitCode = consumeOutputSyncAndReturnExitCode(channel, stdout, stdoutConsumer, stderr, stderrConsumer);

      return exitCode == 0;

  } finally {
      if (stdout != null) {
    stdout.close();
      }
      if (stderr != null) {
    stderr.close();
      }
      if (channel != null) {
    channel.disconnect();
      }
  }
    }
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

        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

            }
        }
    }

    protected void uploadTo(Session session, URL url, String path) {
        Channel channel = null;
        try (InputStream is = url.openStream()) {
            channel = session.openChannel("sftp");
            channel.connect();
            ChannelSftp sftpChannel = (ChannelSftp) channel;
            final CountDownLatch uploadLatch = new CountDownLatch(1);

            sftpChannel.put(is, path, new SftpProgressMonitor() {
                @Override
                public void init(int op, String src, String dest, long max) {
                }
                @Override
                public boolean count(long count) {
                    try {
                        return is.available() > 0;
                    } catch (IOException e) {
                        return false;
                    }
                }

                @Override
                public void end() {
                    uploadLatch.countDown();
                }
            }, ChannelSftp.OVERWRITE);

            uploadLatch.await(10, TimeUnit.MINUTES);
        } catch (Exception e) {
            LOGGER.warn("Failed to upload. Will attempt downloading distribution via maven.");
        } finally {
            if (channel != null) {
                channel.disconnect();
            }
        }
    }
View Full Code Here

           
            // 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

            session.setPassword(fsdef.getPassword());
        }
        session.connect();

        //Open a new session for SFTP.
        Channel channel = session.openChannel("sftp");
        channel.connect();

        //checking SSH client connection.
        if (!channel.isConnected()) {
            logger.warn("Cannot connect with SSH to {}@{}", fsdef.getUsername(),
                    fsdef.getServer());
            throw new RuntimeException("Can not connect to " + fsdef.getUsername() + "@" + fsdef.getServer());
        }
        if (logger.isDebugEnabled()) logger.debug("SSH connection successful");
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.