List of usage examples for org.apache.commons.net.ftp FTPFile isDirectory
public boolean isDirectory()
From source file:org.martin.ftp.model.TCRFiles.java
@Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { JLabel lbl = new JLabel(); ImageIcon icon;//from w ww. ja v a 2s. c om FTPFile file = files.get(row); if (column == 0) { if (file.isDirectory()) icon = new ImageIcon(getClass().getResource("/org/martin/ftp/resources/folder.png")); else icon = new ImageIcon(getClass().getResource("/org/martin/ftp/resources/file.png")); lbl.setIcon(icon); lbl.setText(file.getName()); } else lbl.setText(value.toString()); Color bg = lbl.getBackground(); if (isSelected) lbl.setBackground(Color.CYAN); else if (row == foundFileIndex) lbl.setBackground(Color.RED); else lbl.setBackground(bg); lbl.setOpaque(true); return lbl; }
From source file:org.martin.ftp.model.TCRSearch.java
@Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { JLabel lbl = new JLabel(); ImageIcon icon;//from ww w. j a v a2 s . co m FTPFile file = files.get(row).getFile(); if (column == 0) { if (file.isDirectory()) icon = new ImageIcon(getClass().getResource("/org/martin/ftp/resources/folder.png")); else icon = new ImageIcon(getClass().getResource("/org/martin/ftp/resources/file.png")); lbl.setIcon(icon); lbl.setText(file.getName()); } else lbl.setText(value.toString()); Color bg = lbl.getBackground(); if (isSelected) lbl.setBackground(Color.CYAN); else lbl.setBackground(bg); lbl.setOpaque(true); return lbl; }
From source file:org.martin.ftp.net.FTPLinker.java
public FTPFileFilter getFilter(Filter filter) { return (FTPFile ftpf) -> { if (filter != null) { switch (filter) { case FILES_ONLY: return ftpf.isFile(); case DIRECTORIES_ONLY: return ftpf.isDirectory(); default: return true; }//from www . j a va2 s .co m } else return true; }; }
From source file:org.martin.ftp.util.RemoteComparator.java
@Override public int compare(FTPFile o1, FTPFile o2) { if (null != option) switch (option) { case DATE: if (order == SortOption.UPWARD) return (int) (o1.getTimestamp().getTimeInMillis() - o2.getTimestamp().getTimeInMillis()); else//from www.ja va2 s.c om return (int) (o2.getTimestamp().getTimeInMillis() - o1.getTimestamp().getTimeInMillis()); case FORMAT: String file1Format = Utilities.getFormat(o1.getName()); String file2Format = Utilities.getFormat(o2.getName()); if (order == SortOption.UPWARD) if (o1.isDirectory() || o2.isDirectory()) { if (o1.isDirectory() && o2.isDirectory()) return idDirectory - idDirectory; else if (o1.isDirectory() && !o2.isDirectory()) return idDirectory - idFile; else return idFile - idDirectory; } else return file1Format.compareToIgnoreCase(file2Format); else if (o1.isDirectory() || o2.isDirectory()) { if (o1.isDirectory() && o2.isDirectory()) return idDirectory - idDirectory; else if (o1.isDirectory() && !o2.isDirectory()) return idFile - idDirectory; else return idDirectory - idFile; } else return file2Format.compareToIgnoreCase(file1Format); case NAME: if (order == SortOption.UPWARD) return o1.getName().compareToIgnoreCase(o2.getName()); else return o2.getName().compareToIgnoreCase(o1.getName()); case SIZE: if (order == SortOption.UPWARD) return (int) (o1.getSize() - o2.getSize()); else return (int) (o2.getSize() - o1.getSize()); case TYPE: if ((o1.isDirectory() && o2.isDirectory()) || (!o1.isDirectory() && !o2.isDirectory())) return idDirectory - idDirectory; if (order == SortOption.UPWARD) if (o1.isDirectory() && !o2.isDirectory()) return idDirectory - idFile; else return idFile - idDirectory; else if (o1.isDirectory() && !o2.isDirectory()) return idFile - idDirectory; else return idDirectory - idFile; default: return 0; } return 0; }
From source file:org.martin.ftp.util.SearchComparator.java
@Override public int compare(FileFiltering o1, FileFiltering o2) { FTPFile fileO1 = o1.getFile(); FTPFile fileO2 = o2.getFile();/*from ww w . j ava 2 s .c o m*/ if (null != option) switch (option) { case DATE: if (order == SortOption.UPWARD) return (int) (fileO1.getTimestamp().getTimeInMillis() - fileO2.getTimestamp().getTimeInMillis()); else return (int) (fileO2.getTimestamp().getTimeInMillis() - fileO1.getTimestamp().getTimeInMillis()); case FORMAT: String file1Format = Utilities.getFormat(fileO1.getName()); String file2Format = Utilities.getFormat(fileO2.getName()); if (order == SortOption.UPWARD) if (fileO1.isDirectory() || fileO2.isDirectory()) { if (fileO1.isDirectory() && fileO2.isDirectory()) return idDirectory - idDirectory; else if (fileO1.isDirectory() && !fileO2.isDirectory()) return idDirectory - idFile; else return idFile - idDirectory; } else return file1Format.compareToIgnoreCase(file2Format); else if (fileO1.isDirectory() || fileO2.isDirectory()) { if (fileO1.isDirectory() && fileO2.isDirectory()) return idDirectory - idDirectory; else if (fileO1.isDirectory() && !fileO2.isDirectory()) return idFile - idDirectory; else return idDirectory - idFile; } else return file2Format.compareToIgnoreCase(file1Format); case NAME: if (order == SortOption.UPWARD) return fileO1.getName().compareToIgnoreCase(fileO2.getName()); else return fileO2.getName().compareToIgnoreCase(fileO1.getName()); case SIZE: if (order == SortOption.UPWARD) return (int) (fileO1.getSize() - fileO2.getSize()); else return (int) (fileO2.getSize() - fileO1.getSize()); case TYPE: if ((fileO1.isDirectory() && fileO2.isDirectory()) || (!fileO1.isDirectory() && !fileO2.isDirectory())) return idDirectory - idDirectory; if (order == SortOption.UPWARD) if (fileO1.isDirectory() && !fileO2.isDirectory()) return idDirectory - idFile; else return idFile - idDirectory; else if (fileO1.isDirectory() && !fileO2.isDirectory()) return idFile - idDirectory; else return idDirectory - idFile; default: return 0; } return 0; }
From source file:org.openconcerto.ftp.FTPUtils.java
static public final void saveR(FTPClient ftp, File local) throws IOException { local.mkdirs();//from w w w . ja v a2s .c om for (FTPFile child : ftp.listFiles()) { final String childName = child.getName(); if (childName.indexOf('.') != 0) { if (child.isDirectory()) { ftp.changeWorkingDirectory(childName); saveR(ftp, new File(local, childName)); ftp.changeToParentDirectory(); } else { final OutputStream outs = new FileOutputStream(new File(local, childName)); ftp.retrieveFile(childName, outs); outs.close(); } } } }
From source file:org.openconcerto.ftp.FTPUtils.java
static public final void rmR(final FTPClient ftp, final String toRm) throws IOException { final String cwd = ftp.printWorkingDirectory(); // si on ne peut cd, le dossier n'existe pas if (ftp.changeWorkingDirectory(toRm)) { recurse(ftp, new ExnClosure<FTPFile, IOException>() { @Override//from w ww .ja v a 2 s . c o m public void executeChecked(FTPFile input) throws IOException { final boolean res; if (input.isDirectory()) res = ftp.removeDirectory(input.getName()); else res = ftp.deleteFile(input.getName()); if (!res) throw new IOException("unable to delete " + input); } }, RecursionType.DEPTH_FIRST); } ftp.changeWorkingDirectory(cwd); ftp.removeDirectory(toRm); }
From source file:org.openconcerto.ftp.FTPUtils.java
static public final void recurse(FTPClient ftp, ExnClosure<FTPFile, ?> c, RecursionType type) throws IOException { for (FTPFile child : ftp.listFiles()) { if (child.getName().indexOf('.') != 0) { if (type == RecursionType.BREADTH_FIRST) c.executeCheckedWithExn(child, IOException.class); if (child.isDirectory()) { ftp.changeWorkingDirectory(child.getName()); recurse(ftp, c, type);/* www. j ava 2s . c o m*/ ftp.changeToParentDirectory(); } if (type == RecursionType.DEPTH_FIRST) c.executeCheckedWithExn(child, IOException.class); } } }
From source file:org.openspice.vfs.ftp.FtpVFolder.java
private List list(final boolean want_folders, final boolean want_files) { // System.err.println( "folders = " + want_folders ); // System.err.println( "files = " + want_files ); try {//www . j a va 2s . com final FTPClient ftpc = this.fvol.getConnectedFTPClient(); final FTPFile[] files = ftpc.listFiles(this.path); // { // System.err.println( "List of files is " + files.length + " long" ); // for ( int n = 0; n < files.length; n++ ) { // System.err.println( "["+n+"]. " + files[n] + " " + ( files[n].isDirectory() ? "d" : "-" ) + ( files[n].isFile() ? "f" : "-" ) ); // } // } final List answer = new ArrayList(); for (int i = 0; i < files.length; i++) { final FTPFile file = files[i]; if (want_folders && file.isDirectory()) { // System.err.println( "adding FOLDER " + file ); answer.add(new FtpVFolder(this.fvol, FtpTools.folderName(this.path, file.getName()))); } else if (want_files && (file.isFile() || file.isSymbolicLink())) { // System.err.println( "adding FILE " + file ); answer.add(FtpVFile.uncheckedMake(this.fvol, FtpTools.fileName(this.path, file.getName()))); } } return answer; } catch (IOException e) { throw new RuntimeException(e); } }
From source file:org.ow2.proactive.scheduler.examples.FTPConnector.java
private List<String> downloadDirectory(FTPClient ftpClient, String parentDir, String currentDir, String saveDir) throws IOException { List<String> filesRelativePathName = new ArrayList<>(); String dirToList = parentDir; if (!currentDir.isEmpty()) { dirToList = Paths.get(dirToList, currentDir).toString(); }//from w w w.j a v a 2 s. c o m FTPFile[] subFiles = ftpClient.listFiles(dirToList); for (FTPFile aFile : subFiles) { String currentFileName = aFile.getName(); if (currentFileName.equals(CURRENT_FOLDER) || currentFileName.equals(PARENT_FOLDER)) { // skip parent directory and the directory itself continue; } String remoteFilePath = Paths.get(parentDir, currentDir, currentFileName).toString(); String savePath = Paths.get(saveDir, parentDir, currentDir, currentFileName).toString(); if (aFile.isDirectory()) { // create the directory savePath inside saveDir makeDirectories(savePath); // download the sub directory filesRelativePathName.addAll(downloadDirectory(ftpClient, dirToList, currentFileName, saveDir)); } else { // download the file filesRelativePathName.add(downloadSingleFile(ftpClient, remoteFilePath, savePath)); } } return filesRelativePathName; }