/** * Get a child directory of this directory. * @param dir the directory to look for * @return the child directory, or null if not found */ public Directory getChild(File dir) { for (Directory current : childDirectories) { if (current.getDirectory().equals(dir)) { return current; } } return null; }
private void sendDirectoryToRemote(final Directory directory, final InputStream in, final OutputStream out) throws IOException { String command = "D0"; command += Integer.toOctalString(getDirMode()); command += " 0 "; command += directory.getDirectory().getName(); command += "\n"; out.write(command.getBytes()); out.flush(); waitForAck(in); sendDirectory(directory, in, out); out.write("E\n".getBytes()); out.flush(); waitForAck(in); }
private Directory createDirectory(final FileSet set) { final DirectoryScanner scanner = set.getDirectoryScanner(getProject()); final String[] files = scanner.getIncludedFiles(); if (files.length == 0) { // skip return null; } Directory root = new Directory(scanner.getBasedir()); Stream.of(files).map(Directory::getPath).forEach(path -> { Directory current = root; File currentParent = scanner.getBasedir(); for (String element : path) { final File file = new File(currentParent, element); if (file.isDirectory()) { current.addDirectory(new Directory(file)); current = current.getChild(file); currentParent = current.getDirectory(); } else if (file.isFile()) { current.addFile(file); } } }); return root; }
private void sendDirectoryToRemote(final ChannelSftp channel, final Directory directory) throws IOException, SftpException { final String dir = directory.getDirectory().getName(); try { channel.stat(dir); } catch (final SftpException e) { // dir does not exist. if (e.id == ChannelSftp.SSH_FX_NO_SUCH_FILE) { channel.mkdir(dir); channel.chmod(getDirMode(), dir); } } channel.cd(dir); sendDirectory(channel, directory); channel.cd(".."); }
current.addDirectory(new Directory(file)); current = current.getChild(file); currentParent = current.getDirectory(); } else if (file.isFile()) { current.addFile(file);
} catch (final SftpException e) { String msg = "Error sending directory"; if (current != null && current.getDirectory() != null) { msg += " '" + current.getDirectory().getName() + "'";