示例#1
0
  protected void addKnownHosts() {
    //
    if ((config.sshKnowHostFile == null) || (config.sshKnowHostFile == null)) {
      logger.debug("addUserIDFiles(): No userConfigDir or knownHostFile configured");
      return;
    }
    // Config director is for example" ~/.ssh/
    String configDir = config.userConfigDir;
    String knownHostsFile = config.sshKnowHostFile;

    FSPath configPath;
    try {
      if (configDir != null) {
        configPath = FSUtil.getDefault().resolvePath(configDir);
        FSPath hostsFile = configPath.resolvePath(knownHostsFile);
        if (hostsFile.exists()) {
          jsch.setKnownHosts(hostsFile.getPathname());
        }
      }
    } catch (IOException e) {
      logger.error(
          "addKnownHosts():Failed to read/acces known hosts file:{}/{} => IOException:{}",
          configDir,
          knownHostsFile,
          e);
      return;
    } catch (JSchException e) {
      logger.error(
          "addKnownHosts():Failed to add known hosts file:{}/{} => JSchException:{}",
          configDir,
          knownHostsFile,
          e);
      return;
    }
  }
示例#2
0
  @Override
  public boolean hasChildren() {
    if (file.isFile()) {
      return false;
    }

    try {
      String[] list = file.list();
      return ((list != null) && (list.length > 0));
    } catch (IOException e) {
      return false;
    }
  }
示例#3
0
 @Override
 protected String doGetResourceType() {
   if (file.isFile()) {
     return FSPath.FILE_TYPE;
   } else {
     return FSPath.DIR_TYPE;
   }
 }
示例#4
0
  protected void addUserIDFiles() {
    //
    if (config.userConfigDir == null) {
      logger.debug("addUserIDFiles(): No userConfigDir configured");
      return;
    }
    // Config director is for example" ~/.ssh/
    String configDir = config.userConfigDir;
    FSPath configPath;

    try {
      configPath = FSUtil.getDefault().resolvePath(configDir);
    } catch (IOException e) {
      logger.error(
          "addUserIDFiles():Failed to read/acces config directory:{} => IOException:{}",
          configDir,
          e);
      return;
    }

    String keys[] = config.privateKeys;
    if ((keys == null) || (keys.length <= 0)) {
      logger.info("addUserIDFiles():No private keys");
      return;
    }

    for (String key : keys) {
      try {
        FSPath keyFile = configPath.resolvePath(key);
        if (keyFile.exists()) {
          logger.info("addUserIDFiles(): adding existing identity:{}\n", keyFile);
          jsch.addIdentity(keyFile.getPathname());
        } else {
          logger.info("addUserIDFiles(): ignoring missing identity file:{}\n", keyFile);
        }
      } catch (IOException e) {
        logger.error("Got IOException accessing file:{}/{} => IOException:{}", configPath, key, e);
      } catch (JSchException e) {
        logger.error("Got JSchException adding file:{}/{} => JSchException:{}", configPath, key, e);
      }
    }
  }
示例#5
0
 @Override
 protected ProxyNode doCreateNew(String type, String optNewName) throws ProxyException {
   try {
     FSPath newPath = file.resolvePath(optNewName);
     if (StringUtil.equals(type, FSPath.FILE_TYPE)) {
       newPath.create();
       return createNewNode(newPath);
     } else if (StringUtil.equals(type, FSPath.FILE_TYPE)) {
       newPath.mkdir();
       return createNewNode(newPath);
     } else {
       throw new ProxyException("Create: unrecognized type:" + type);
     }
   } catch (FileURISyntaxException e) {
     throw new ProxyException("Invalid location:" + optNewName + "\n" + e.getMessage(), e);
   } catch (IOException e) {
     throw new ProxyException(
         "Couldn't create new " + type + " " + optNewName + "\n" + e.getMessage(), e);
   }
 }
示例#6
0
  @Override
  public List<? extends ProxyNode> doGetChilds(int offset, int range, LongHolder numChildsLeft)
      throws ProxyException {
    FSPath[] files;
    try {
      files = file.listNodes();
    } catch (IOException e) {
      throw new ProxyException("Couldn't list contents:" + this, e);
    }

    if (files == null) {
      return null;
    }

    ArrayList<FSNodeProxyNode> nodes = new ArrayList<FSNodeProxyNode>(files.length);

    for (int i = 0; i < files.length; i++) {
      nodes.add(createNewNode(files[i]));
    }

    return subrange(nodes, offset, range);
  }
示例#7
0
 @Override
 public String getName() {
   return file.getBasename();
 }
示例#8
0
 @Override
 protected String doGetMimeType() throws ProxyException {
   return MimeTypes.getDefault().getMimeType(file.getPathname());
 }
示例#9
0
 protected FSNodeProxyNode createNewNode(FSPath fsNode) throws ProxyException {
   return new FSNodeProxyNode(getProxyFactory(), new VRL(fsNode.getURI()), fsNode);
 }