Package org.jclouds.sshj

Examples of org.jclouds.sshj.SshjSshClient


         this.injector = injector;
      }

      @Override
      public SshClient create(HostAndPort socket, LoginCredentials credentials) {
         SshClient client = new SshjSshClient(backoffLimitedRetryHandler, socket, credentials, timeout, getAgentConnector());
         injector.injectMembers(client);// add logger
         return client;
      }
View Full Code Here


         this.injector = injector;
      }

      @Override
      public SshClient create(HostAndPort socket, LoginCredentials credentials) {
         SshClient client = new SshjSshClient(backoffLimitedRetryHandler, socket, credentials, timeout);
         injector.injectMembers(client);// add logger
         return client;
      }
View Full Code Here

         this.injector = injector;
      }

      @Override
      public SshClient create(HostAndPort socket, LoginCredentials credentials) {
         SshClient client = new SshjSshClient(backoffLimitedRetryHandler, socket, credentials, timeout);
         injector.injectMembers(client);// add logger
         return client;
      }
View Full Code Here

         this.injector = injector;
      }

      @Override
      public SshClient create(HostAndPort socket, LoginCredentials credentials) {
         SshClient client = new SshjSshClient(backoffLimitedRetryHandler, socket, credentials, timeout, getAgentConnector());
         injector.injectMembers(client);// add logger
         return client;
      }
View Full Code Here

    try {
      File tmpFile = createTmpDir();
      String fileLocation = tmpFile.getAbsolutePath() + file.getName();
      fileOutputStream = new FileOutputStream(fileLocation);

      final SshjSshClient client = getSSHClient(url, privateKey);
      inputStream = client.get(fileName).openStream();

      FileCopyUtils.copy(inputStream, fileOutputStream);
      return fileLocation;
    }
    catch (IOException ioException) {
View Full Code Here

    Assert.notNull(dir, "dir should not be null");
    Assert.hasText(fileName, "The remote file name must be specified.");
    boolean isFileCopied = false;
    long timeout = System.currentTimeMillis() + retryTime;
    while (!isFileCopied && System.currentTimeMillis() < timeout) {
      SshjSshClient client = getSSHClient(host, privateKey);
      client.exec("mkdir " + dir);
      client.put(dir + "/" + fileName, payload);
      ExecResponse response = client.exec("ls -al " + dir + "/" + fileName);
      if (response.getExitStatus() > 0) {
        continue; //file was not created
      }
      response = client.exec("cat " + dir + "/" + fileName);
      if (response.getExitStatus() > 0 || !payload.equals(response.getOutput())) {
        continue;//data stored on machine is different than was expected.
      }
      isFileCopied = true;
    }
View Full Code Here

    Assert.notNull(uri, "uri should not be null");
    Assert.notNull(file, "file must not be null");
    boolean isFileCopied = false;
    long timeout = System.currentTimeMillis() + waitTime;
    while (!isFileCopied && System.currentTimeMillis() < timeout) {
      final SshjSshClient client = getSSHClient(host, privateKey);
      Assert.isTrue(file.exists(), "File to be copied to remote machine does not exist");
      ByteSource byteSource = com.google.common.io.Files.asByteSource(file);
      ByteSourcePayload payload = new ByteSourcePayload(byteSource);
      long byteSourceSize = -1;
      try {
        byteSourceSize = byteSource.size();
        payload.getContentMetadata().setContentLength(byteSourceSize);
      }
      catch (IOException ioe) {
        throw new IllegalStateException("Unable to retrieve size for file to be copied to remote machine.", ioe);
      }
      client.put(uri.getPath(), payload);
      if (client.exec("ls -al " + uri.getPath()).getExitStatus() == 0) {
        ExecResponse statResponse = client.exec("stat --format=%s " + uri.getPath());
        long copySize = Long.valueOf(statResponse.getOutput().trim());
        if (copySize == byteSourceSize) {
          isFileCopied = true;
        }
      }
View Full Code Here

    Assert.hasText(path, "path must not be empty nor null");
    Assert.hasText(host, "host must not be empty nor null");
    Assert.hasText(privateKey, "privateKey must not be empty nor null");
    long timeout = System.currentTimeMillis() + waitTime;
    while (!isDirectoryCreated && System.currentTimeMillis() < timeout) {
      SshjSshClient client = getSSHClient(host, privateKey);
      client.exec("mkdir " + path);
      ExecResponse response = client.exec("ls -al " + path);
      if (response.getExitStatus() > 0) {
        continue; //directory was not created
      }
      isDirectoryCreated = true;
    }
View Full Code Here

    Assert.hasText(privateKey, "privateKey must not be empty nor null.");
    Assert.hasText(host, "The remote machine's URL must be specified.");
    Assert.notNull(dir, "dir should not be null");
    Assert.hasText(fileName, "The remote file name must be specified.");

    final SshjSshClient client = getSSHClient(host, privateKey);
    client.exec("echo '" + payload + "' >> " + dir + "/" + fileName);
  }
View Full Code Here

   * @return An Integer array that contains the pids.
   */
  public static Integer[] getContainerPidsFromURL(URL url, String privateKey, String jpsCommand) {
    Assert.notNull(url, "url can not be null");
    Assert.hasText(privateKey, "privateKey can not be empty nor null");
    SshjSshClient client = getSSHClient(url, privateKey);
    ExecResponse response = client.exec(jpsCommand);
    return extractPidsFromJPS(response.getOutput());
  }
View Full Code Here

TOP

Related Classes of org.jclouds.sshj.SshjSshClient

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.