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; } }
@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; } }
@Override protected String doGetResourceType() { if (file.isFile()) { return FSPath.FILE_TYPE; } else { return FSPath.DIR_TYPE; } }
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); } } }
@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); } }
@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); }
@Override public String getName() { return file.getBasename(); }
@Override protected String doGetMimeType() throws ProxyException { return MimeTypes.getDefault().getMimeType(file.getPathname()); }
protected FSNodeProxyNode createNewNode(FSPath fsNode) throws ProxyException { return new FSNodeProxyNode(getProxyFactory(), new VRL(fsNode.getURI()), fsNode); }