Package ch.ethz.ssh2

Examples of ch.ethz.ssh2.Connection


    setURI(remote.getURI());
  }
 
  public void connect() throws HgAuthFailedException, HgRemoteConnectionException, HgRuntimeException {
    try {
      conn = new Connection(uri.getHost(), uri.getPort() == -1 ? 22 : uri.getPort());
      conn.connect();
      authenticateClient();
    } catch (IOException ex) {
      throw new HgRemoteConnectionException("Failed to establish connection").setServerInfo(getServerLocation());
    }
View Full Code Here


          for (int j=0; j<ipList.getLength(); j++) {
            Element itemVariableElement = (Element) ipList.item(j);
           
            s_logger.info("Attempting to SSH into agent " + itemVariableElement.getTextContent());
            try {
              Connection conn = new Connection(itemVariableElement.getTextContent());
            conn.connect(null, 60000, 60000);

            s_logger.info("SSHed successfully into agent " + itemVariableElement.getTextContent());

            boolean isAuthenticated = conn.authenticateWithPassword("root",
                "password");

            if (isAuthenticated == false) {
              s_logger.info("Authentication failed for root with password");
              return false;
            }
           
            Session sess = conn.openSession();
            s_logger.info("Executing : " + commandElement.getTextContent());
            sess.execCommand(commandElement.getTextContent());
            Thread.sleep(60000);
            sess.close();
            conn.close();
           
            } catch (Exception ex) {
              s_logger.error(ex);
              return false;
           
View Full Code Here

       
        if (api.getName().equals("rebootManagementServer")) {
           
          s_logger.info("Attempting to SSH into management server " + this.getParam().get("hostip"));
          try {
            Connection conn = new Connection(this.getParam().get("hostip"));
          conn.connect(null, 60000, 60000);

          s_logger.info("SSHed successfully into management server " + this.getParam().get("hostip"));

          boolean isAuthenticated = conn.authenticateWithPassword("root",
              "password");

          if (isAuthenticated == false) {
            s_logger.info("Authentication failed for root with password");
            return false;
          }
         
          String restartCommand = "service cloud-management restart; service cloud-usage restart";
          Session sess = conn.openSession();
          s_logger.info("Executing : " + restartCommand);
          sess.execCommand(restartCommand);
          Thread.sleep(120000);
          sess.close();
          conn.close();
         
          } catch (Exception ex) {
            s_logger.error(ex);
            return false;
         
View Full Code Here

          Thread.sleep(300000);
        }
       
        s_logger.info("Attempting to SSH into windows host " + host + " with retry attempt: " + retry);
       
        Connection conn = new Connection(host);
        conn.connect(null, 60000, 60000);
       
        s_logger.info("SSHed successfully into windows host " + host);
        boolean success = false;
        boolean isAuthenticated = conn.authenticateWithPassword("vmops", "vmops");
        if (isAuthenticated == false) {
          return "Authentication failed";
        }
        SCPClient scp = new SCPClient(conn);
       
        scp.put("wget.exe", "");
       
        Session sess = conn.openSession();
        s_logger.info("Executing : wget http://172.16.0.220/dump.bin");
        sess.execCommand("wget http://172.16.0.220/dump.bin && dir dump.bin");
       
        InputStream stdout = sess.getStdout();
        InputStream stderr = sess.getStderr();
       
        byte[] buffer = new byte[8192];
        while (true) {
          if ((stdout.available() == 0) && (stderr.available() == 0)) {
            int conditions = sess.waitForCondition(ChannelCondition.STDOUT_DATA | ChannelCondition.STDERR_DATA
                | ChannelCondition.EOF, 120000);
           
            if ((conditions & ChannelCondition.TIMEOUT) != 0) {
              s_logger.info("Timeout while waiting for data from peer.");
              return null;
            }
           
            if ((conditions & ChannelCondition.EOF) != 0) {
              if ((conditions & (ChannelCondition.STDOUT_DATA | ChannelCondition.STDERR_DATA)) == 0) {
                break;
              }
            }
          }
         
          while (stdout.available() > 0) {
            success = true;
            int len = stdout.read(buffer);
            if (len > 0) // this check is somewhat paranoid
              s_logger.info(new String(buffer, 0, len));
          }
   
          while (stderr.available() > 0) {
            int len = stderr.read(buffer);
          }
        }
        sess.close();
        conn.close();
       
        if (success) {
          return null;
        } else {
          retry++;
View Full Code Here

          Thread.sleep(120000);
        }
       
        s_logger.info("Attempting to SSH into linux host " + host + " with retry attempt: " + retry);
       
        Connection conn = new Connection(host);
        conn.connect(null, 60000, 60000);
       
        s_logger.info("SSHed successfully into linux host " + host);
   
        boolean isAuthenticated = conn.authenticateWithPassword("root", "password");
   
        if (isAuthenticated == false) {
          return "Authentication failed";
        }
        boolean success = false;
        Session sess = conn.openSession();
        s_logger.info("Executing : wget http://172.16.0.220/dump.bin");
        sess.execCommand("wget http://172.16.0.220/dump.bin && ls -al dump.bin");
       
        InputStream stdout = sess.getStdout();
        InputStream stderr = sess.getStderr();
       
        byte[] buffer = new byte[8192];
        while (true) {
          if ((stdout.available() == 0) && (stderr.available() == 0)) {
            int conditions = sess.waitForCondition(ChannelCondition.STDOUT_DATA | ChannelCondition.STDERR_DATA
                | ChannelCondition.EOF, 120000);
           
            if ((conditions & ChannelCondition.TIMEOUT) != 0) {
              s_logger.info("Timeout while waiting for data from peer.");
              return null;
            }
           
            if ((conditions & ChannelCondition.EOF) != 0) {
              if ((conditions & (ChannelCondition.STDOUT_DATA | ChannelCondition.STDERR_DATA)) == 0) {
                break;
              }
            }
          }
         
          while (stdout.available() > 0) {
            success = true;
            int len = stdout.read(buffer);
            if (len > 0) // this check is somewhat paranoid
              s_logger.info(new String(buffer, 0, len));
          }
   
          while (stderr.available() > 0) {
            int len = stderr.read(buffer);
          }
        }
       
        sess.close();
        conn.close();
       
        if (success) {
          return null;
        } else {
          retry++;
View Full Code Here

                    Thread.sleep(300000);
                }

                s_logger.info("Attempting to SSH into windows host " + host + " with retry attempt: " + retry + " for account " + _account.get());

                Connection conn = new Connection(host);
                conn.connect(null, 60000, 60000);

                s_logger.info("User " + _account.get() + " ssHed successfully into windows host " + host);
                boolean success = false;
                boolean isAuthenticated = conn.authenticateWithPassword("Administrator", "password");
                if (isAuthenticated == false) {
                    return "Authentication failed";
                } else {
                    s_logger.info("Authentication is successfull");
                }

                try {
                    SCPClient scp = new SCPClient(conn);
                    scp.put("wget.exe", "wget.exe", "C:\\Users\\Administrator", "0777");
                    s_logger.info("Successfully put wget.exe file");
                } catch (Exception ex) {
                    s_logger.error("Unable to put wget.exe " + ex);
                }

                if (conn == null) {
                    s_logger.error("Connection is null");
                }
                Session sess = conn.openSession();

                s_logger.info("User + " + _account.get() + " executing : wget http://" + downloadUrl);
                String downloadCommand = "wget http://" + downloadUrl + " && dir dump.bin";
                sess.execCommand(downloadCommand);

                InputStream stdout = sess.getStdout();
                InputStream stderr = sess.getStderr();

                byte[] buffer = new byte[8192];
                while (true) {
                    if ((stdout.available() == 0) && (stderr.available() == 0)) {
                        int conditions = sess.waitForCondition(ChannelCondition.STDOUT_DATA | ChannelCondition.STDERR_DATA | ChannelCondition.EOF, 120000);

                        if ((conditions & ChannelCondition.TIMEOUT) != 0) {
                            s_logger.info("Timeout while waiting for data from peer.");
                            return null;
                        }

                        if ((conditions & ChannelCondition.EOF) != 0) {
                            if ((conditions & (ChannelCondition.STDOUT_DATA | ChannelCondition.STDERR_DATA)) == 0) {
                                break;
                            }
                        }
                    }

                    while (stdout.available() > 0) {
                        success = true;
                        int len = stdout.read(buffer);
                        if (len > 0) // this check is somewhat paranoid
                            s_logger.info(new String(buffer, 0, len));
                    }

                    while (stderr.available() > 0) {
                        /* int len = */stderr.read(buffer);
                    }
                }
                sess.close();
                conn.close();

                if (success) {
                    return null;
                } else {
                    retry++;
View Full Code Here

                    Thread.sleep(120000);
                }

                s_logger.info("Attempting to SSH into linux host " + host + " with retry attempt: " + retry + ". Account is " + _account.get());

                Connection conn = new Connection(host);
                conn.connect(null, 60000, 60000);

                s_logger.info("User + " + _account.get() + " ssHed successfully into linux host " + host);

                boolean isAuthenticated = conn.authenticateWithPassword("root", password);

                if (isAuthenticated == false) {
                    s_logger.info("Authentication failed for root with password" + password);
                    return "Authentication failed";

                }

                boolean success = false;
                String linuxCommand = null;

                if (i % 10 == 0)
                    linuxCommand = "rm -rf *; wget http://" + downloadUrl + " && ls -al dump.bin";
                else
                    linuxCommand = "wget http://" + downloadUrl + " && ls -al dump.bin";

                Session sess = conn.openSession();
                s_logger.info("User " + _account.get() + " executing : " + linuxCommand);
                sess.execCommand(linuxCommand);

                InputStream stdout = sess.getStdout();
                InputStream stderr = sess.getStderr();

                byte[] buffer = new byte[8192];
                while (true) {
                    if ((stdout.available() == 0) && (stderr.available() == 0)) {
                        int conditions = sess.waitForCondition(ChannelCondition.STDOUT_DATA | ChannelCondition.STDERR_DATA | ChannelCondition.EOF, 120000);

                        if ((conditions & ChannelCondition.TIMEOUT) != 0) {
                            s_logger.info("Timeout while waiting for data from peer.");
                            return null;
                        }

                        if ((conditions & ChannelCondition.EOF) != 0) {
                            if ((conditions & (ChannelCondition.STDOUT_DATA | ChannelCondition.STDERR_DATA)) == 0) {
                                break;
                            }
                        }
                    }

                    while (stdout.available() > 0) {
                        success = true;
                        int len = stdout.read(buffer);
                        if (len > 0) // this check is somewhat paranoid
                            s_logger.info(new String(buffer, 0, len));
                    }

                    while (stderr.available() > 0) {
                        /* int len = */stderr.read(buffer);
                    }
                }

                sess.close();
                conn.close();

                if (!success) {
                    retry++;
                    if (retry == MAX_RETRY_LINUX) {
                        result = "SSH Linux Network test fail";
View Full Code Here

                }

                s_logger.info("Attempting to SSH into windows host " + host
                        + " with retry attempt: " + retry + " for account " + _account.get());

                Connection conn = new Connection(host);
                conn.connect(null, 60000, 60000);

                s_logger.info("User " + _account.get() + " ssHed successfully into windows host " + host);
                boolean success = false;
                boolean isAuthenticated = conn.authenticateWithPassword(
                        "Administrator", "password");
                if (isAuthenticated == false) {
                    return "Authentication failed";
                }
                else {
                    s_logger.info("Authentication is successfull");
                }

                try {
                    SCPClient scp = new SCPClient(conn);
                    scp.put("wget.exe", "wget.exe", "C:\\Users\\Administrator", "0777");
                    s_logger.info("Successfully put wget.exe file");
                } catch (Exception ex) {
                    s_logger.error("Unable to put wget.exe " + ex);
                }

                if (conn == null ){
                    s_logger.error("Connection is null");
                }
                Session sess = conn.openSession();

                s_logger.info("User + " + _account.get() + " executing : wget http://192.168.1.250/dump.bin");
                sess
                .execCommand("wget http://192.168.1.250/dump.bin && dir dump.bin");

                InputStream stdout = sess.getStdout();
                InputStream stderr = sess.getStderr();

                byte[] buffer = new byte[8192];
                while (true) {
                    if ((stdout.available() == 0) && (stderr.available() == 0)) {
                        int conditions = sess.waitForCondition(
                                ChannelCondition.STDOUT_DATA
                                | ChannelCondition.STDERR_DATA
                                | ChannelCondition.EOF, 120000);

                        if ((conditions & ChannelCondition.TIMEOUT) != 0) {
                            s_logger
                            .info("Timeout while waiting for data from peer.");
                            return null;
                        }

                        if ((conditions & ChannelCondition.EOF) != 0) {
                            if ((conditions & (ChannelCondition.STDOUT_DATA | ChannelCondition.STDERR_DATA)) == 0) {
                                break;
                            }
                        }
                    }

                    while (stdout.available() > 0) {
                        success = true;
                        int len = stdout.read(buffer);
                        if (len > 0) // this check is somewhat paranoid
                            s_logger.info(new String(buffer, 0, len));
                    }

                    while (stderr.available() > 0) {
                        /* int len = */stderr.read(buffer);
                    }
                }
                sess.close();
                conn.close();

                if (success) {
                    Thread.sleep(120000);
                    return null;
                } else {
View Full Code Here

                }

                s_logger.info("Attempting to SSH into linux host " + host
                        + " with retry attempt: " + retry + ". Account is " + _account.get());

                Connection conn = new Connection(host);
                conn.connect(null, 60000, 60000);

                s_logger.info("User + " + _account.get() + " ssHed successfully into linux host " + host);

                boolean isAuthenticated = conn.authenticateWithPassword("root",
                        password);

                if (isAuthenticated == false) {
                    s_logger.info("Authentication failed for root with password" + password);
                    return "Authentication failed";

                }

                boolean success = false;
                String linuxCommand = null;

                if (i % 10 == 0)
                    linuxCommand = "rm -rf *; wget http://192.168.1.250/dump.bin && ls -al dump.bin";
                else
                    linuxCommand = "wget http://192.168.1.250/dump.bin && ls -al dump.bin";

                Session sess = conn.openSession();
                s_logger.info("User " + _account.get() + " executing : " + linuxCommand);
                sess.execCommand(linuxCommand);

                InputStream stdout = sess.getStdout();
                InputStream stderr = sess.getStderr();


                byte[] buffer = new byte[8192];
                while (true) {
                    if ((stdout.available() == 0) && (stderr.available() == 0)) {
                        int conditions = sess.waitForCondition(
                                ChannelCondition.STDOUT_DATA
                                | ChannelCondition.STDERR_DATA
                                | ChannelCondition.EOF, 120000);

                        if ((conditions & ChannelCondition.TIMEOUT) != 0) {
                            s_logger
                            .info("Timeout while waiting for data from peer.");
                            return null;
                        }

                        if ((conditions & ChannelCondition.EOF) != 0) {
                            if ((conditions & (ChannelCondition.STDOUT_DATA | ChannelCondition.STDERR_DATA)) == 0) {
                                break;
                            }
                        }
                    }

                    while (stdout.available() > 0) {
                        success = true;
                        int len = stdout.read(buffer);
                        if (len > 0) // this check is somewhat paranoid
                            s_logger.info(new String(buffer, 0, len));
                    }

                    while (stderr.available() > 0) {
                        /* int len = */stderr.read(buffer);
                    }
                }

                sess.close();
                conn.close();

                if (!success) {
                    retry++;
                    if (retry == MAX_RETRY_LINUX) {
                        result = "SSH Linux Network test fail";
View Full Code Here

          }
          for (VirtualMachine vm: this.virtualMachines ){
           
              s_logger.info("Attempting to SSH into linux host " + this.publicIp
                  + " with retry attempt: " + retry);
              Connection conn = new Connection(this.publicIp);
              conn.connect(null, 600000, 600000);

              s_logger.info("SSHed successfully into linux host " + this.publicIp);

              boolean isAuthenticated = conn.authenticateWithPassword("root",
                  "password");

              if (isAuthenticated == false) {
                s_logger.info("Authentication failed");
              }
              //execute copy command
              Session sess = conn.openSession();
              String fileName;
              Random ran = new Random();
              fileName=Math.abs(ran.nextInt())+"-file";
              String copyCommand = new String ("./scpScript "+vm.getPrivateIp()+" "+fileName);
              s_logger.info("Executing " + copyCommand);
              sess.execCommand(copyCommand);
              Thread.sleep(120000);
              sess.close();
             
              //execute wget command
              sess = conn.openSession();
              String downloadCommand = new String ("wget http://172.16.0.220/scripts/checkDiskSpace.sh; chmod +x *sh; ./checkDiskSpace.sh; rm -rf checkDiskSpace.sh");
              s_logger.info("Executing " + downloadCommand);
              sess.execCommand(downloadCommand);
              Thread.sleep(120000);
              sess.close();
             
              //close the connection
              conn.close();
            }
          }catch (Exception ex) {
              s_logger.error(ex);
              retry++;
              if (retry == retryNum) {
View Full Code Here

TOP

Related Classes of ch.ethz.ssh2.Connection

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.