List of usage examples for org.apache.commons.net.ftp FTPFile getName
public String getName()
From source file:org.isatools.isacreator.filechooser.FTPBrowser.java
/** * Return all the files in the directory. Also groups files into categories here for output in the JTree * * @param top - The TreeNode to add to.// w ww . ja v a 2s . com */ public void getFilesInDirectory(FileBrowserTreeNode top) { try { FTPFile[] contents = ftpClient.listFiles(); if (contents != null) { for (FTPFile f : contents) { if (f.isDirectory()) { dirFiles.put(f.getName(), f); top.add(new FileBrowserTreeNode(f.getName(), false, FileBrowserTreeNode.DIRECTORY)); } else { String extension = f.getName().substring(f.getName().lastIndexOf(".") + 1).trim() .toUpperCase(); if (fileMap.get(extension) == null) { fileMap.put(extension, new ArrayList<Object>()); } // add to file map all the extensions, for addition to the tree node in a later step. fileMap.get(extension).add(f); } } } } catch (IOException e) { log.error(e.getMessage()); } }
From source file:org.jason.mapmaker.server.service.ShapefileMetadataServiceImpl.java
private List<String> getRemoteFilenames(String url, String directory) { FTPClient ftp = new FTPClient(); List<String> filenameList = new ArrayList<String>(); try {/*from w w w .j a va 2 s. com*/ int reply; ftp.connect(url); reply = ftp.getReplyCode(); if (!FTPReply.isPositiveCompletion(reply)) { ftp.disconnect(); System.out.println("FTP connection failed for " + url); } ftp.enterLocalPassiveMode(); ftp.login("anonymous", ""); FTPFile[] files = ftp.listFiles(directory); for (FTPFile f : files) { filenameList.add(f.getName()); } ftp.logout(); } catch (IOException ex) { ex.printStackTrace(); } return filenameList; }
From source file:org.jevis.commons.driver.DataSourceHelper.java
public static List<String> getFTPMatchedFileNames(FTPClient fc, DateTime lastReadout, String filePath) { filePath = filePath.replace("\\", "/"); String[] pathStream = getPathTokens(filePath); String startPath = ""; if (filePath.startsWith("/")) { startPath = "/"; }//from w ww .jav a2s .c o m List<String> folderPathes = getMatchingPathes(startPath, pathStream, new ArrayList<String>(), fc, lastReadout, new DateTimeFormatterBuilder()); // System.out.println("foldersize,"+folderPathes.size()); List<String> fileNames = new ArrayList<String>(); if (folderPathes.isEmpty()) { org.apache.log4j.Logger.getLogger(DataSourceHelper.class).log(org.apache.log4j.Level.ERROR, "Cant find suitable folder on the device"); return fileNames; } // String fileName = null; String fileNameScheme = pathStream[pathStream.length - 1]; String currentfolder = null; try { for (String folder : folderPathes) { // fc.changeWorkingDirectory(folder); // System.out.println("currentFolder,"+folder); currentfolder = folder; // for (FTPFile file : fc.listFiles(folder)) { // System.out.println(file.getName()); // } fc.changeWorkingDirectory(folder); for (FTPFile file : fc.listFiles()) { // org.apache.log4j.Logger.getLogger(Launcher.class.getName()).log(org.apache.log4j.Level.ALL, "CurrentFileName: " + fileName); // fileName = removeFoler(fileName, folder); if (file.getTimestamp().compareTo(lastReadout.toGregorianCalendar()) < 0) { continue; } boolean match = false; System.out.println(file.getName()); if (DataSourceHelper.containsTokens(fileNameScheme)) { boolean matchDate = matchDateString(file.getName(), fileNameScheme); DateTime folderTime = getFileTime(folder + file.getName(), pathStream); boolean isLater = folderTime.isAfter(lastReadout); if (matchDate && isLater) { match = true; } } else { Pattern p = Pattern.compile(fileNameScheme); Matcher m = p.matcher(file.getName()); match = m.matches(); } if (match) { fileNames.add(folder + file.getName()); } } } } catch (IOException ex) { org.apache.log4j.Logger.getLogger(DataSourceHelper.class).log(org.apache.log4j.Level.ERROR, ex.getMessage()); } catch (Exception ex) { org.apache.log4j.Logger.getLogger(DataSourceHelper.class).log(org.apache.log4j.Level.ERROR, "Error while searching a matching file"); org.apache.log4j.Logger.getLogger(DataSourceHelper.class).log(org.apache.log4j.Level.ERROR, "Folder: " + currentfolder); org.apache.log4j.Logger.getLogger(DataSourceHelper.class).log(org.apache.log4j.Level.ERROR, "FileName: " + fileNameScheme); org.apache.log4j.Logger.getLogger(DataSourceHelper.class).log(org.apache.log4j.Level.ERROR, ex.getMessage()); } if (folderPathes.isEmpty()) { org.apache.log4j.Logger.getLogger(DataSourceHelper.class).log(org.apache.log4j.Level.ERROR, "Cant find suitable files on the device"); } // System.out.println("filenamesize"+fileNames.size()); return fileNames; }
From source file:org.jevis.commons.driver.DataSourceHelper.java
private static List<String> getMatchingPathes(String path, String[] pathStream, ArrayList<String> arrayList, FTPClient fc, DateTime lastReadout, DateTimeFormatterBuilder dtfbuilder) { int nextTokenPos = getPathTokens(path).length; if (nextTokenPos == pathStream.length - 1) { arrayList.add(path);// ww w.j a v a 2 s . c o m return arrayList; } String nextToken = pathStream[nextTokenPos]; String nextFolder = null; try { if (containsDateToken(nextToken)) { FTPFile[] listDirectories = fc.listFiles(path); // DateTimeFormatter ftmTemp = getDateFormatter(nextToken); for (FTPFile folder : listDirectories) { if (!matchDateString(folder.getName(), nextToken)) { continue; } // System.out.println("listdir," + folder.getName()); // if (containsDate(folder.getName(), ftmTemp)) { DateTime folderTime = getFolderTime(path + folder.getName() + "/", pathStream); if (folderTime.isAfter(lastReadout)) { nextFolder = folder.getName(); // System.out.println("dateFolder," + nextFolder); getMatchingPathes(path + nextFolder + "/", pathStream, arrayList, fc, lastReadout, dtfbuilder); } // } } } else { nextFolder = nextToken; // System.out.println("normalFolder," + nextFolder); getMatchingPathes(path + nextFolder + "/", pathStream, arrayList, fc, lastReadout, dtfbuilder); } } catch (IOException ex) { org.apache.log4j.Logger.getLogger(DataSourceHelper.class).log(org.apache.log4j.Level.ERROR, ex.getMessage()); } return arrayList; }
From source file:org.martin.ftp.gui.GUIClient.java
private void setWorkingDirectory() throws IOException { FTPFile selected = getSelectedFile(); selectedIndex = tblFiles.getSelectedRow(); if (selected.isDirectory()) { linker.setWorkingDirectory(directorioActual + "/" + selected.getName()); updateTable();/*from w ww. j av a 2 s. c o m*/ } else { dialogFileOptions.show(); // // // int tipo = JOptionPane.INFORMATION_MESSAGE; // int tipoOp = JOptionPane.YES_NO_OPTION; // int opcionSi = JOptionPane.YES_OPTION; // int opcion = JOptionPane.showConfirmDialog( // gestion, // "Desea descargar el archivo?", // "Confirmacion de Descarga", // tipoOp, // tipo); // // if (opcion == opcionSi) { // try { // downloadFile(selected); // } catch (IOException ex) { // Logger.getLogger(Cliente.class.getName()).log(Level.SEVERE, null, ex); // } // } } }
From source file:org.martin.ftp.gui.GUIClient.java
private void downloadFile(FTPFile selected) throws IOException { fileChoos.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fileChoos.showOpenDialog(this); File directory = fileChoos.getSelectedFile(); if (directory != null) linker.downloadFile(selected.getName(), directory.getPath()); }
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 w w .j av a 2 s . c o m*/ 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;/* ww w .j a va2s . 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
/** * // w w w . j av a 2 s .c om * @param nombre Nombre del archivo a buscar * @param type Tipo --> si es directorio o archivo * @return Archivo obtenido dentro de la ruta actual, sino se encuentra retorna null * @throws IOException */ public FTPFile getFile(String nombre, Type type) throws IOException { FTPFile resultado = null; if (type == Type.FILE) { for (FTPFile file : getFiles()) if (file.getName().equalsIgnoreCase(nombre)) { resultado = file; break; } } else { for (FTPFile dir : getDirectories()) if (dir.getName().equalsIgnoreCase(nombre)) { resultado = dir; break; } } return resultado; }
From source file:org.martin.ftp.net.FTPLinker.java
public FTPFile getFile(String nombre, String directorio, Type type) throws IOException { FTPFile resultado = null;/*from www . ja v a2s. co m*/ if (type == Type.FILE) { for (FTPFile file : getFiles(directorio)) if (file.getName().equalsIgnoreCase(nombre)) { resultado = file; break; } } else { for (FTPFile dir : getDirectories(directorio)) if (dir.getName().equalsIgnoreCase(nombre)) { resultado = dir; break; } } return resultado; }