Package com.trilead.ssh2

Examples of com.trilead.ssh2.SFTPv3Client


       
        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

      boolean isAuthenticated = false;
      this.setSshConnection(new Connection(this.host, this.port));

      if (proxyHost != null && this.proxyHost.length() > 0) {
        if (this.proxyUser != null && this.proxyUser.length() > 0) {
          this.getSshConnection().setProxyData(new HTTPProxyData(this.proxyHost, this.proxyPort));
        }
        else {
          this.getSshConnection().setProxyData(
              new HTTPProxyData(this.proxyHost, this.proxyPort, this.proxyUser, SOSCommandline.getExternalPassword(this.proxyPassword, logger)));
        }
      }

      this.getSshConnection().connect();
View Full Code Here

      String strHostName = objCO.getHost().Value();
      int intPortNo = objCO.getPort().value();
      this.setSshConnection(new Connection(strHostName, intPortNo));

      if (objCO.getProxy_host().IsNotEmpty()) {
        HTTPProxyData objProxy = null;
        if (objCO.getProxy_user().IsEmpty()) {
          objProxy = new HTTPProxyData(objCO.getProxy_host().Value(), objCO.getProxy_port().value());
        }
        else {
          objProxy = new HTTPProxyData(objCO.getProxy_host().Value(), objCO.getProxy_port().value(), objCO.getProxy_user().Value(),
              objCO.getProxy_password().Value());
        }
        this.getSshConnection().setProxyData(objProxy);
      }
      this.getSshConnection().connect();
View Full Code Here

            boolean isAuthenticated = false;
            this.setSshConnection(new Connection(this.getHost(), this.getPort()));
               
            if (this.getProxyHost() != null && this.getProxyHost().length() > 0) {
                if (this.getProxyUser() != null && this.getProxyUser().length() > 0) {
                    this.getSshConnection().setProxyData(new HTTPProxyData(this.getProxyHost(), this.getProxyPort()));
                } else {
                    this.getSshConnection().setProxyData(new HTTPProxyData(this.getProxyHost(), this.getProxyPort(), this.getProxyUser(), this.getProxyPassword()));
                }
            }
               
            this.getSshConnection().connect();
View Full Code Here

TOP

Related Classes of com.trilead.ssh2.SFTPv3Client

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.