private boolean buildDirectoryChunks(String dirName) throws IOException { final StringBuilder sb = new StringBuilder(dirName.length()); final String[] dirs = dirName.split("/|\\\\"); boolean success = false; for (String dir : dirs) { sb.append(dir).append('/'); // must normalize the directory name String directory = endpoint.getConfiguration().normalizePath(sb.toString()); // do not try to build root folder (/ or \) if (!(directory.equals("/") || directory.equals("\\"))) { log.trace("Trying to build remote directory by chunk: {}", directory); // while creating directory string if directory results in // trailing slash, remove it not necessary directory = FileUtil.stripTrailingSeparator(directory); success = client.makeDirectory(directory); } } return success; }
private static String buildUrl(String scheme, String hostname, Object port, String path, String uri) { // build together from component level and given uri that has additional context path to append String build = scheme + "://" + hostname; if (port != null) { build += ":" + port; } if (path != null) { build = FileUtil.stripTrailingSeparator(build); build += "/" + path; } String query = null; if (uri != null && uri.contains("?")) { query = StringHelper.after(uri, "?"); uri = StringHelper.before(uri, "?"); uri = StringHelper.after(uri, "://"); } // remaining is to be appending if (uri != null) { build = FileUtil.stripTrailingSeparator(build); build += "/" + uri; } if (query != null) { build += "?" + query; } return build; }
private static String buildUrl(String scheme, String hostname, Object port, String path, String uri) { // build together from component level and given uri that has additional context path to append String build = scheme + "://" + hostname; if (port != null) { build += ":" + port; } if (path != null) { build = FileUtil.stripTrailingSeparator(build); build += "/" + path; } String query = null; if (uri != null && uri.contains("?")) { query = StringHelper.after(uri, "?"); uri = StringHelper.before(uri, "?"); uri = StringHelper.after(uri, "://"); } // remaining is to be appending if (uri != null) { build = FileUtil.stripTrailingSeparator(build); build += "/" + uri; } if (query != null) { build += "?" + query; } return build; }
@Override protected boolean pollDirectory(String fileName, List<GenericFile<SftpRemoteFile>> fileList, int depth) { String currentDir = null; if (isStepwise()) { // must remember current dir so we stay in that directory after the poll currentDir = operations.getCurrentDirectory(); } // strip trailing slash fileName = FileUtil.stripTrailingSeparator(fileName); boolean answer = doPollDirectory(fileName, null, fileList, depth); if (currentDir != null) { operations.changeCurrentDirectory(currentDir); } return answer; }
@Override protected boolean pollDirectory(String fileName, List<GenericFile<FTPFile>> fileList, int depth) { String currentDir = null; if (isStepwise()) { // must remember current dir so we stay in that directory after the poll currentDir = operations.getCurrentDirectory(); } // strip trailing slash fileName = FileUtil.stripTrailingSeparator(fileName); boolean answer = doPollDirectory(fileName, null, fileList, depth); if (currentDir != null) { operations.changeCurrentDirectory(currentDir); } return answer; }
dirName = FileUtil.stripTrailingSeparator(dirName);
contextPath = FileUtil.stripTrailingSeparator(contextPath); contextPath = FileUtil.stripLeadingSeparator(contextPath); if (ObjectHelper.isNotEmpty(contextPath)) {
dirName = FileUtil.stripTrailingSeparator(dirName);
contextPath = FileUtil.stripTrailingSeparator(contextPath); contextPath = FileUtil.stripLeadingSeparator(contextPath); if (ObjectHelper.isNotEmpty(contextPath)) {
contextPath = FileUtil.stripTrailingSeparator(contextPath); contextPath = FileUtil.stripLeadingSeparator(contextPath); if (ObjectHelper.isNotEmpty(contextPath)) {
String dir = FileUtil.stripTrailingSeparator(absolutePath); String fileName = file.getName(); if (((FtpConfiguration) endpoint.getConfiguration()).isHandleDirectoryParserAbsoluteResult()) {
private RemoteFile<SftpRemoteFile> asRemoteFile(String absolutePath, SftpRemoteFile file, String charset) { RemoteFile<SftpRemoteFile> answer = new RemoteFile<>(); answer.setCharset(charset); answer.setEndpointPath(endpointPath); answer.setFile(file); answer.setFileNameOnly(file.getFilename()); answer.setFileLength(file.getFileLength()); answer.setLastModified(file.getLastModified()); answer.setHostname(((RemoteFileConfiguration) endpoint.getConfiguration()).getHost()); answer.setDirectory(file.isDirectory()); // absolute or relative path boolean absolute = FileUtil.hasLeadingSeparator(absolutePath); answer.setAbsolute(absolute); // create a pseudo absolute name String dir = FileUtil.stripTrailingSeparator(absolutePath); String absoluteFileName = FileUtil.stripLeadingSeparator(dir + "/" + file.getFilename()); // if absolute start with a leading separator otherwise let it be relative if (absolute) { absoluteFileName = "/" + absoluteFileName; } answer.setAbsoluteFilePath(absoluteFileName); // the relative filename, skip the leading endpoint configured path String relativePath = ObjectHelper.after(absoluteFileName, endpointPath); // skip trailing / relativePath = FileUtil.stripLeadingSeparator(relativePath); answer.setRelativeFilePath(relativePath); // the file name should be the relative path answer.setFileName(answer.getRelativeFilePath()); return answer; }