List of usage examples for org.apache.commons.net.ftp FTPFile getType
public int getType()
_TYPE
constants), e.g., if it is a directory, a regular file, or a symbolic link. From source file:Main.java
public static void main(String[] args) { FTPClient client = new FTPClient(); client.connect("ftp.domain.com"); client.login("admin", "secret"); String[] names = client.listNames(); for (String name : names) { System.out.println("Name = " + name); }//from w w w . j a v a 2 s . co m FTPFile[] ftpFiles = client.listFiles(); for (FTPFile ftpFile : ftpFiles) { // Check if FTPFile is a regular file if (ftpFile.getType() == FTPFile.FILE_TYPE) { System.out.println("FTPFile: " + ftpFile.getName() + "; " + FileUtils.byteCountToDisplaySize(ftpFile.getSize())); } } client.logout(); client.disconnect(); }
From source file:com.savy3.util.MainframeFTPClientUtils.java
public static List<String> listSequentialDatasets(String pdsName, Configuration conf) throws IOException { List<String> datasets = new ArrayList<String>(); FTPClient ftp = null;//from w w w.j a v a 2 s .c o m try { ftp = getFTPConnection(conf); if (ftp != null) { ftp.changeWorkingDirectory("'" + pdsName + "'"); FTPFile[] ftpFiles = ftp.listFiles(); for (FTPFile f : ftpFiles) { if (f.getType() == FTPFile.FILE_TYPE) { datasets.add(f.getName()); } } } } catch (IOException ioe) { throw new IOException("Could not list datasets from " + pdsName + ":" + ioe.toString()); } finally { if (ftp != null) { closeFTPConnection(ftp); } } return datasets; }
From source file:models.Indexer.java
public int indexFtpServer() { try {/*from w w w . j a v a 2 s .c om*/ ftpClient.connect(ftp_address); boolean login = ftpClient.login("anonymous", ""); if (login) { System.out.println("Connection established..."); // get all files from server and store them in an array of // FTPFiles FTPFile[] files = ftpClient.listFiles(); ArrayList<String> all_files = new ArrayList<>(); for (FTPFile cur_file : files) { if (cur_file.getType() == FTPFile.FILE_TYPE) { String file_name = cur_file.getName(); if (file_name.endsWith(".pdf")) all_files.add(file_name); } } downloadAndIndex(all_files); // logout the user, returned true if logout successfully boolean logout = ftpClient.logout(); if (logout) { System.out.println("Connection close..."); } } else { System.out.println("Connection fail..."); } } catch (IOException ex) { System.out.println("Error to connect ftp server where the corpus is stored"); Logger.getLogger(Indexer.class.getName()).log(Level.SEVERE, null, ex); } return num_of_docs_indexed; }
From source file:models.LocalIndexer.java
public int indexFtpServer() { try {//from www . jav a 2s .c o m ftpClient.connect(ftp_address); boolean login = ftpClient.login("anonymous", ""); if (login) { System.out.println("Connection established..."); // get all files from server and store them in an array of // FTPFiles FTPFile[] files = ftpClient.listFiles(); ArrayList<String> all_files = new ArrayList<>(); for (FTPFile cur_file : files) { if (cur_file.getType() == FTPFile.FILE_TYPE) { String file_name = cur_file.getName(); if (file_name.endsWith(".pdf")) all_files.add(file_name); } } downloadAndIndex(all_files); // logout the user, returned true if logout successfully boolean logout = ftpClient.logout(); if (logout) { System.out.println("Connection close..."); } } else { System.out.println("Connection fail..."); } } catch (IOException ex) { System.out.println("Error to connect ftp server where the corpus is stored"); Logger.getLogger(LocalIndexer.class.getName()).log(Level.SEVERE, null, ex); } return num_of_docs_indexed; }
From source file:de.ep3.ftpc.model.CrawlerDirectories.java
/** * Provides the next file or directory in the current stack. * * Since this is a state machine, it will return a different results on * consecutive calls./*from ww w. ja v a 2 s . com*/ * * @return File, directory or null, if finished. * @throws IOException */ public CrawlerFile getNextFile() throws IOException { if (directoryStack.isEmpty()) { if (includePaths.isEmpty()) { return null; } String nextIncludePath = includePaths.firstElement(); includePaths.remove(nextIncludePath); directoryStack.push(new CrawlerDirectory(ftpClient, nextIncludePath)); } CrawlerDirectory currentDirectory = directoryStack.peek(); FTPFile file = currentDirectory.getNextFile(); if (file == null) { directoryStack.pop(); return getNextFile(); } if (file.getType() == FTPFile.DIRECTORY_TYPE) { String nextPath = currentDirectory.getPath() + file.getName(); if (!excludePaths.contains(nextPath)) { directoryStack.push(new CrawlerDirectory(ftpClient, nextPath)); } } return new CrawlerFile(file, currentDirectory.getPath()); }
From source file:ch.cyberduck.core.ftp.parser.MicrosoftFTPEntryParserTest.java
@Test public void testParse() throws Exception { FTPFile parsed; // #3701// ww w.j a v a 2 s . c o m parsed = parser.parseFTPEntry("12-04-06 12:43PM 65335 fon1.kucuk.jpg"); assertNotNull(parsed); assertEquals("fon1.kucuk.jpg", parsed.getName()); assertEquals(FTPFile.FILE_TYPE, parsed.getType()); assertEquals(65335, parsed.getSize()); assertEquals(2006, parsed.getTimestamp().get(Calendar.YEAR)); assertEquals(Calendar.DECEMBER, parsed.getTimestamp().get(Calendar.MONTH)); assertEquals(4, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH)); }
From source file:au.org.intersect.dms.wn.transports.impl.FtpConnection.java
private FileInfo makeFileInfo(String parentPath, FTPFile info) { Date date = info.getTimestamp().getTime(); int ftpType = info.getType(); if (ftpType == FTPFile.SYMBOLIC_LINK_TYPE) { try {/*from w w w . j av a2 s . co m*/ changeWorkingDirectory(PathUtils.joinPath(parentPath, info.getName())); ftpType = FTPFile.DIRECTORY_TYPE; } catch (IOException e) { throw new TransportException("Cannot get list directory (" + info.getName() + ")"); } catch (PathNotFoundException e) { ftpType = FTPFile.FILE_TYPE; } } FileType type = ftpType == FTPFile.DIRECTORY_TYPE ? FileType.DIRECTORY : FileType.FILE; FileInfo item = new FileInfo(type, PathUtils.joinPath(parentPath, info.getName()), info.getName(), info.getSize(), date); return item; }
From source file:ch.cyberduck.core.ftp.parser.WebstarFTPEntryParserTest.java
@Test public void testParse() throws Exception { FTPFile parsed; parsed = parser.parseFTPEntry("-rwx------ 17 332 640 Dec 20 08:54 file 1"); assertNotNull(parsed);// w w w . ja v a2s. com assertEquals("file 1", parsed.getName()); assertEquals(FTPFile.FILE_TYPE, parsed.getType()); assertEquals(640, parsed.getSize()); parsed = parser.parseFTPEntry("drwx------ folder 2 Dec 20 08:55 folder1"); assertNotNull(parsed); assertEquals("folder1", parsed.getName()); assertEquals(FTPFile.DIRECTORY_TYPE, parsed.getType()); assertEquals(Calendar.DECEMBER, parsed.getTimestamp().get(Calendar.MONTH)); assertEquals(20, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH)); assertTrue(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION)); assertFalse(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.READ_PERMISSION)); assertFalse(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.READ_PERMISSION)); assertTrue(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.WRITE_PERMISSION)); assertFalse(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.WRITE_PERMISSION)); assertFalse(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.WRITE_PERMISSION)); assertTrue(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.EXECUTE_PERMISSION)); assertFalse(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.EXECUTE_PERMISSION)); assertFalse(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.EXECUTE_PERMISSION)); }
From source file:ch.cyberduck.core.ftp.parser.OpensolarisFTPEntryParserTest.java
@Test public void testParse() throws Exception { FTPFile parsed; // #3689/*from w w w . j ava 2 s .c o m*/ parsed = parser.parseFTPEntry("drwxr-xr-x+ 5 niels staff 7 Sep 6 13:46 data"); assertNotNull(parsed); assertEquals(parsed.getName(), "data"); assertEquals(FTPFile.DIRECTORY_TYPE, parsed.getType()); assertEquals(7, parsed.getSize()); assertEquals(Calendar.SEPTEMBER, parsed.getTimestamp().get(Calendar.MONTH)); assertEquals(6, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH)); assertTrue(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION)); assertTrue(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.WRITE_PERMISSION)); assertTrue(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.EXECUTE_PERMISSION)); assertTrue(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.READ_PERMISSION)); assertTrue(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.EXECUTE_PERMISSION)); assertTrue(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.READ_PERMISSION)); assertTrue(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.EXECUTE_PERMISSION)); }
From source file:ch.cyberduck.core.ftp.parser.FilezillaFTPEntryParserTest.java
@Test public void testParse() throws Exception { FTPFile parsed; // #3119/*www.j a v a 2s .co m*/ parsed = parser.parseFTPEntry("-rw-r--r-- 1 ftp ftp 100847 Sep 10 2004 octfront2.jpg"); assertNotNull(parsed); assertEquals("octfront2.jpg", parsed.getName()); assertEquals(FTPFile.FILE_TYPE, parsed.getType()); assertEquals(100847, parsed.getSize()); assertEquals(Calendar.SEPTEMBER, parsed.getTimestamp().get(Calendar.MONTH)); assertEquals(10, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH)); assertTrue(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION)); assertTrue(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.READ_PERMISSION)); assertTrue(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.READ_PERMISSION)); assertTrue(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.WRITE_PERMISSION)); }