Package com.trilead.ssh2.packets

Examples of com.trilead.ssh2.packets.PacketGlobalTrileadPing


                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);
                }
View Full Code Here


      if (!SSHCmdHelper.sshExecuteCmd(sshConnection, "[ -f '/usr/sbin/dhcpd' ]")) {
        throw new ConfigurationException("Cannot find dhcpd.conf /etc/dhcpd.conf at  on " + _ip);
      }

      SCPClient scp = new SCPClient(sshConnection);

      String editHosts = "scripts/network/exdhcp/dhcpd_edithosts.py";
      String editHostsPath = Script.findScript("", editHosts);
      if (editHostsPath == null) {
        throw new ConfigurationException("Can not find script dnsmasq_edithosts.sh at " + editHosts);
      }
      scp.put(editHostsPath, "/usr/bin/", "0755");
     
      String prepareDhcpdScript = "scripts/network/exdhcp/prepare_dhcpd.sh";
      String prepareDhcpdScriptPath = Script.findScript("", prepareDhcpdScript);
      if (prepareDhcpdScriptPath == null) {
        throw new ConfigurationException("Can not find prepare_dhcpd.sh at " + prepareDhcpdScriptPath);
      }
      scp.put(prepareDhcpdScriptPath, "/usr/bin/", "0755");
     
      //TODO: tooooooooooooooo ugly here!!!
      String[] ips = _ip.split("\\.");
      ips[3] = "0";
      StringBuffer buf = new StringBuffer();
View Full Code Here

        }
      }

    } catch (Exception e) {
      if (e instanceof SFTPException) {
        SFTPException sftpExp = (SFTPException) e;
        if (sftpExp.getServerErrorCode() != 2)
          sftpExp.printStackTrace();
      } else
        e.printStackTrace();

    }
View Full Code Here

  }

  public File transferCommandScript(File commandFile, boolean isWindows) throws Exception {
    try {
      SFTPv3Client sftpClient = new SFTPv3Client(this.getSshConnection());
      SFTPv3FileAttributes attr = new SFTPv3FileAttributes();
      attr.permissions = new Integer(0700);

      boolean exists = true;
      // check if File already exists
      while (exists) {
        try {
          SFTPv3FileAttributes attribs = sftpClient.stat(commandFile.getName());
        }
        catch (SFTPException e) {
          getLogger().debug9("Error code when checking file existence: " + e.getServerErrorCode());
          exists = false;
        }
        if (exists) {
          getLogger().debug1("file with that name already exists, trying new name...");
          String suffix = (isWindows ? ".cmd" : ".sh");
          File resultFile = File.createTempFile("sos", suffix);
          resultFile.delete();
          commandFile.renameTo(resultFile);
          commandFile = resultFile;
        }
      }

      // set execute permissions for owner
      SFTPv3FileHandle fileHandle = sftpClient.createFileTruncate(commandFile.getName(), attr);

      FileInputStream fis = null;
      long offset = 0;
      try {
        fis = new FileInputStream(commandFile);
        byte[] buffer = new byte[1024];
        while (true) {
          int len = fis.read(buffer, 0, buffer.length);
          if (len <= 0)
            break;
          sftpClient.write(fileHandle, offset, buffer, 0, len);
          offset += len;
        }
        fis.close();
        fis = null;

      }
      catch (Exception e) {
        throw new Exception("error occurred writing file [" + commandFile.getName() + "]: " + e.getMessage());
      }
      finally {
        if (fis != null)
          try {
            fis.close();
            fis = null;
          }
          catch (Exception ex) {
          } // gracefully ignore this error
      }
      sftpClient.closeFile(fileHandle);

      fileHandle = null;
      sftpClient.close();
      return commandFile;
    }
    catch (Exception e) {
      throw new Exception("Error transferring command script: " + e, e);
    }
View Full Code Here

    }
  }

  private void deleteCommandScript(String commandFile) throws Exception {
    try {
      SFTPv3Client sftpClient = new SFTPv3Client(this.getSshConnection());
      sftpClient.rm(commandFile);
      sftpClient.close();
    }
    catch (Exception e) {
      getLogger().warn("Failed to delete remote command script: " + e);
    }
  }
View Full Code Here

    }
  }

  private SFTPv3Client FtpClient() throws Exception {
    if (sftpClient == null) {
      sftpClient = new SFTPv3Client(this.getSshConnection());
    }
    return sftpClient;
  }
View Full Code Here

            if (!isAuthenticated) throw new Exception("authentication failed [host=" + this.getHost() + ", port=" + this.getPort() + ", user:" + this.getUser()
                    + ", auth_method=" + this.getAuthenticationMethod() + ", auth_file=" + this.getAuthenticationFilename());

           
            sftpClient = new SFTPv3Client(sshConnection);
            connected = true;
            reply = "OK";
        } catch (Exception e) {
          reply = e.toString();
            if (sshConnection != null) try { disconnect(); } catch (Exception ex) {} // gracefully ignore this error
View Full Code Here

  }

  private SFTPv3Client Client() {
    if (objFTPClient == null) {
      try {
        objFTPClient = new SFTPv3Client(sshConnection);
      }
      catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
View Full Code Here

      }
      Vector files = sftpClient.ls(pathname);     
      String[] rvFiles = new String[files.size()];
     
      for(int i=0; i<files.size();i++){
        SFTPv3DirectoryEntry entry = (SFTPv3DirectoryEntry) files.get(i);
        rvFiles[i] = entry.filename;
     
      reply = "ls OK";
      return rvFiles;
    } catch(Exception e){
View Full Code Here

      return rvVector;
    }
    Vector files = sftpClient.ls(pathname);     
         
    for(int i=0; i<files.size();i++){
      SFTPv3DirectoryEntry entry = (SFTPv3DirectoryEntry) files.get(i);
      if (!entry.attributes.isDirectory()) rvVector.add(entry.filename);
    }   
    reply = "ls OK";
    return rvVector;
   
View Full Code Here

TOP

Related Classes of com.trilead.ssh2.packets.PacketGlobalTrileadPing

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.