示例#1
0
文件: SSHTest2.java 项目: lzupb/mybae
  public static void main(String[] args) {
    String hostname = "123.57.48.109";
    String username = "******";
    String password = "******";

    try {
      /* Create a connection instance */

      Connection conn = new Connection(hostname);

      /* Now connect */

      conn.connect();

      /* Authenticate */

      boolean isAuthenticated = conn.authenticateWithPassword(username, password);

      if (isAuthenticated == false) throw new IOException("Authentication failed.");

      /* Create a session */

      SCPClient scpclient = conn.createSCPClient();

      scpclient.get("/alidata/account.log", "D:\\temp");

      /* Close the connection */

      conn.close();

    } catch (IOException e) {
      e.printStackTrace(System.err);
      System.exit(2);
    }
  }
  @OnEvent(component = "UpdateClusterParamsForm", value = "submit")
  @Secured("ROLE_ADMIN")
  Object onUpdateClusterParamsForm() {
    String info = "Update: Ok<br/>";
    info += dataSource.updateParams(cluster);
    Cache.refreshClusterParams();

    if (!cluster.isLocal()) {
      try {
        Connection conn =
            PublicKeyAuthentication.connect(
                cluster.getUsername(),
                cluster.getHostname(),
                cluster.getPrivateKeyPath(),
                cluster.getPassphrase());
        if (conn != null) {
          conn.close();
        }
      } catch (Exception e) {
        info = e.getMessage();
        e.printStackTrace();
      }
    }

    infoPage.setUp(info, "Updating cluster params:");

    return infoPage;
  }
  public static void main(String[] args) throws IOException {
    String hostname = "somehost";
    String username = "******";
    String password = "******";

    File knownHosts = new File("~/.ssh/known_hosts");

    try {
      /* Load known_hosts file into in-memory database */

      if (knownHosts.exists()) database.addHostkeys(knownHosts);

      /* Create a connection instance */

      Connection conn = new Connection(hostname);

      /* Now connect and use the SimpleVerifier */

      conn.connect(new SimpleVerifier(database));

      /* Authenticate */

      boolean isAuthenticated = conn.authenticateWithPassword(username, password);

      if (isAuthenticated == false) throw new IOException("Authentication failed.");

      /* Create a session */

      Session sess = conn.openSession();

      sess.execCommand("uname -a && date && uptime && who");

      InputStream stdout = new StreamGobbler(sess.getStdout());
      BufferedReader br = new BufferedReader(new InputStreamReader(stdout));

      System.out.println("Here is some information about the remote host:");

      while (true) {
        String line = br.readLine();
        if (line == null) break;
        System.out.println(line);
      }

      /* Close this session */

      sess.close();

      /* Close the connection */

      conn.close();

    } catch (IOException e) {
      e.printStackTrace(System.err);
      System.exit(2);
    }
  }
示例#4
0
  public static void main(String[] args) {
    String hostname = "127.0.0.1";
    String username = "******";

    File keyfile = new File("~/.ssh/id_rsa"); // or "~/.ssh/id_dsa"
    String keyfilePass = "******"; // will be ignored if not needed

    try {
      /* Create a connection instance */

      Connection conn = new Connection(hostname);

      /* Now connect */

      conn.connect();

      /* Authenticate */

      boolean isAuthenticated = conn.authenticateWithPublicKey(username, keyfile, keyfilePass);

      if (isAuthenticated == false) throw new IOException("Authentication failed.");

      /* Create a session */

      Session sess = conn.openSession();

      sess.execCommand("uname -a && date && uptime && who");

      InputStream stdout = new StreamGobbler(sess.getStdout());

      BufferedReader br = new BufferedReader(new InputStreamReader(stdout));

      System.out.println("Here is some information about the remote host:");

      while (true) {
        String line = br.readLine();
        if (line == null) break;
        System.out.println(line);
      }

      /* Close this session */

      sess.close();

      /* Close the connection */

      conn.close();

    } catch (IOException e) {
      e.printStackTrace(System.err);
      System.exit(2);
    }
  }
示例#5
0
  static void increaseCPU(OnDemandAWS pc, String keyName) throws InterruptedException {

    File keyfile = new File(keyName + ".pem"); // or "~/.ssh/id_dsa"
    String keyfilePass = "******"; // will be ignored if not needed

    try {
      Connection conn = new Connection(pc.ipAddress);
      conn.connect();

      boolean isAuthenticated = conn.authenticateWithPublicKey("ec2-user", keyfile, keyfilePass);
      if (isAuthenticated == false) throw new IOException("Authentication failed.");

      Session sess = conn.openSession();
      System.out.println("Increasing CPU usage for " + pc.machineName);
      sess.execCommand("while true; do true; done");
      sess.close();
      conn.close();

    } catch (IOException e) {
      e.printStackTrace(System.err);
      System.out.println("Please use the attached script to start and stop cpu remotely");
    }
  }
示例#6
0
 public void disconnect() {
   connection.close();
 }
 @Override
 public void disconnect() throws Throwable {
   ganymedConn.close();
 }