Ejemplo n.º 1
0
 @Override
 public ChannelSftp create() throws JSchException {
   checkConnected();
   String channel = "sftp";
   sftp = (ChannelSftp) sessionConnection.getSession().openChannel(channel);
   sftp.connect();
   return sftp;
 }
Ejemplo n.º 2
0
 public JschSshClient(
     ProxyConfig proxyConfig,
     BackoffLimitedRetryHandler backoffLimitedRetryHandler,
     HostAndPort socket,
     LoginCredentials loginCredentials,
     int timeout) {
   this.user = checkNotNull(loginCredentials, "loginCredentials").getUser();
   this.host = checkNotNull(socket, "socket").getHostText();
   checkArgument(socket.getPort() > 0, "ssh port must be greater then zero" + socket.getPort());
   checkArgument(
       loginCredentials.getPassword() != null || loginCredentials.getPrivateKey() != null,
       "you must specify a password or a key");
   this.backoffLimitedRetryHandler =
       checkNotNull(backoffLimitedRetryHandler, "backoffLimitedRetryHandler");
   if (loginCredentials.getPrivateKey() == null) {
     this.toString =
         String.format(
             "%s:pw[%s]@%s:%d",
             loginCredentials.getUser(),
             base16()
                 .lowerCase()
                 .encode(md5().hashString(loginCredentials.getPassword(), UTF_8).asBytes()),
             host,
             socket.getPort());
   } else {
     String fingerPrint = fingerprintPrivateKey(loginCredentials.getPrivateKey());
     String sha1 = sha1PrivateKey(loginCredentials.getPrivateKey());
     this.toString =
         String.format(
             "%s:rsa[fingerprint(%s),sha1(%s)]@%s:%d",
             loginCredentials.getUser(), fingerPrint, sha1, host, socket.getPort());
   }
   sessionConnection =
       SessionConnection.builder()
           .hostAndPort(HostAndPort.fromParts(host, socket.getPort()))
           .loginCredentials(loginCredentials)
           .proxy(checkNotNull(proxyConfig, "proxyConfig"))
           .connectTimeout(timeout)
           .sessionTimeout(timeout)
           .build();
 }
Ejemplo n.º 3
0
    @Override
    public ExecChannel create() throws Exception {
      this.sessionConnection =
          acquire(
              SessionConnection.builder()
                  .from(JschSshClient.this.sessionConnection)
                  .sessionTimeout(0)
                  .build());
      String channel = "exec";
      executor = (ChannelExec) sessionConnection.openChannel(channel);
      executor.setCommand(command);
      executor.setErrStream(new ByteArrayOutputStream());
      InputStream inputStream = executor.getInputStream();
      InputStream errStream = executor.getErrStream();
      OutputStream outStream = executor.getOutputStream();
      executor.connect();
      return new ExecChannel(
          outStream,
          inputStream,
          errStream,
          new Supplier<Integer>() {

            @Override
            public Integer get() {
              int exitStatus = executor.getExitStatus();
              return exitStatus != -1 ? exitStatus : null;
            }
          },
          new Closeable() {

            @Override
            public void close() throws IOException {
              clear();
            }
          });
    }
Ejemplo n.º 4
0
 protected Builder fromSessionConnection(SessionConnection in) {
   return hostAndPort(in.getHostAndPort())
       .connectTimeout(in.getConnectTimeout())
       .loginCredentials(in.getLoginCredentials());
 }
Ejemplo n.º 5
0
 @PreDestroy
 public void disconnect() {
   sessionConnection.clear();
 }
Ejemplo n.º 6
0
 private void checkConnected() {
   checkState(
       sessionConnection.getSession() != null && sessionConnection.getSession().isConnected(),
       String.format("(%s) Session not connected!", toString()));
 }