private String buildRemotePath(String parent, String child) { String remotePath = null; if (parent != null) { remotePath = (parent + child); } else if (StringUtils.hasText(child)) { remotePath = "." + this.remoteFileTemplate.getRemoteFileSeparator() + child; } return remotePath; }
/** * @param remoteFilePath The remote file path. * @return The remote file name. */ protected String getRemoteFilename(String remoteFilePath) { int index = remoteFilePath.lastIndexOf(this.remoteFileTemplate.getRemoteFileSeparator()); if (index < 0) { return remoteFilePath; } else { return remoteFilePath.substring(index + 1); } }
/** * Move one remote path to another. * The message can be consulted to determine some context; * isn't used in the default implementation. * @param message the request message related to this move command * @param session the remote protocol session to perform move command * @param remoteFilePath the source remote path * @param remoteFileNewPath the target remote path * @return true or false as a result of the operation * @throws IOException the IO exception during performing remote command * @since 5.0 */ protected boolean mv(Message<?> message, Session<F> session, String remoteFilePath, String remoteFileNewPath) throws IOException { int lastSeparator = remoteFileNewPath.lastIndexOf(this.remoteFileTemplate.getRemoteFileSeparator()); if (lastSeparator > 0) { String remoteFileDirectory = remoteFileNewPath.substring(0, lastSeparator + 1); RemoteFileUtils.makeDirectories(remoteFileDirectory, session, this.remoteFileTemplate.getRemoteFileSeparator(), this.logger); } session.rename(remoteFilePath, remoteFileNewPath); return true; }
private void processFile(Session<F> session, String directory, String subDirectory, List<F> lsFiles, boolean recursion, F file) throws IOException { if (this.options.contains(Option.SUBDIRS) || !isDirectory(file)) { if (recursion && StringUtils.hasText(subDirectory)) { lsFiles.add(enhanceNameWithSubDirectory(file, subDirectory)); } else { lsFiles.add(file); } } String fileName = getFilename(file); if (recursion && isDirectory(file) && !(".".equals(fileName)) && !("..".equals(fileName))) { lsFiles.addAll(listFilesInRemoteDir(session, directory, subDirectory + fileName + this.remoteFileTemplate.getRemoteFileSeparator())); } }
private Object doNlst(Message<?> requestMessage) { String dir = this.fileNameProcessor != null ? this.fileNameProcessor.processMessage(requestMessage) : null; if (dir != null && !dir.endsWith(this.remoteFileTemplate.getRemoteFileSeparator())) { dir += this.remoteFileTemplate.getRemoteFileSeparator(); } final String fullDir = dir; List<?> payload = this.remoteFileTemplate.execute(session -> nlst(requestMessage, session, fullDir)); return getMessageBuilderFactory() .withPayload(payload) .setHeader(FileHeaders.REMOTE_DIRECTORY, dir); }
private Object doLs(Message<?> requestMessage) { String dir = this.fileNameProcessor != null ? this.fileNameProcessor.processMessage(requestMessage) : null; if (dir != null && !dir.endsWith(this.remoteFileTemplate.getRemoteFileSeparator())) { dir += this.remoteFileTemplate.getRemoteFileSeparator(); } final String fullDir = dir; List<?> payload = this.remoteFileTemplate.execute(session -> ls(requestMessage, session, fullDir)); return getMessageBuilderFactory() .withPayload(payload) .setHeader(FileHeaders.REMOTE_DIRECTORY, dir); }
subDirectory + this.remoteFileTemplate.getRemoteFileSeparator() : "") + filteredFile.getName(); replies.addAll(putLocalDirectory(requestMessage, filteredFile, newSubDirectory));