List of usage examples for org.apache.commons.net.ftp FTPFile getName
public String getName()
From source file:com.github.fge.ftpfs.io.commonsnetimpl.CommonsNetFtpAgent.java
@Override public FtpFileView getFileView(final String name) throws IOException { try {//from ww w . jav a 2 s .co m ftpClient.setFileType(FTP.ASCII_FILE_TYPE); final FTPFile[] files = ftpClient.listFiles(name); if (files.length == 0) throw new NoSuchFileException(name); if (files.length == 1) return new CommonsNetFtpFileView(files[0]); for (final FTPFile file : files) if (".".equals(file.getName())) return new CommonsNetFtpFileView(file); throw new IllegalStateException(); } catch (FTPConnectionClosedException e) { status = Status.DEAD; throw new IOException("service unavailable", e); } }
From source file:com.github.fge.ftpfs.io.commonsnetimpl.CommonsNetFtpAgent.java
@Override public EnumSet<AccessMode> getAccess(final String name) throws IOException { try {//from ww w . j a v a 2 s .co m ftpClient.setFileType(FTP.ASCII_FILE_TYPE); final FTPFile[] files = ftpClient.listFiles(name); if (files.length == 0) throw new NoSuchFileException(name); if (files.length == 1) return calculateAccess(files[0]); for (final FTPFile file : files) if (".".equals(file.getName())) return calculateAccess(file); throw new IllegalStateException(); } catch (FTPConnectionClosedException e) { status = Status.DEAD; throw new IOException("service unavailable", e); } }
From source file:net.redwarp.actions.ftp.CustomFTPClient.java
private boolean isFilenameInFTPDirectory(String filename, FTPFile[] filesInDirectory) { for (FTPFile file : filesInDirectory) { if (filename.equals(file.getName())) { return true; }// w w w .ja v a 2s.co m } return false; }
From source file:ch.cyberduck.core.ftp.parser.HPTru64ParserTest.java
/** * http://trac.cyberduck.ch/ticket/2246/*from w w w . ja v a2 s.c o m*/ */ @Test public void testParse() throws Exception { FTPFile parsed; parsed = parser.parseFTPEntry("drwxr-xr-x 7 ToysPKG advertise 8192 Jun 24 11:58 Private Label Mock"); assertNotNull(parsed); assertEquals(parsed.getName(), "Private Label Mock"); assertEquals(FTPFile.DIRECTORY_TYPE, parsed.getType()); assertEquals("ToysPKG", parsed.getUser()); assertEquals("advertise", parsed.getGroup()); assertEquals(8192, parsed.getSize()); assertEquals(Calendar.JUNE, parsed.getTimestamp().get(Calendar.MONTH)); assertEquals(24, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH)); parsed = parser.parseFTPEntry( "-rw-r--r-- 1 ToysPKG advertise24809879 Jun 25 10:54 TRU-Warning Guide Master CD.sitx"); assertNull(parsed); }
From source file:com.knowbout.epg.processor.Downloader.java
private boolean downloadFile(FTPFile remoteFile) throws IOException { boolean success = false; File file = new File(destinationFolder + File.separator + remoteFile.getName()); long lastModified = remoteFile.getTimestamp().getTimeInMillis(); log.debug("Remote file is " + remoteFile.getName() + " local file is " + file.getAbsoluteFile() + " does it exist:" + file.exists()); if (forceDownload || !file.exists() || (file.lastModified() < lastModified)) { log.debug("Downloading " + remoteFile.getName() + " " + remoteFile.getSize() + " to " + file.getAbsolutePath()); FileOutputStream fos = new FileOutputStream(file); client.retrieveFile(remoteFile.getName(), fos); fos.close();/*from w w w.jav a2 s . c om*/ fos.flush(); file.setLastModified(lastModified); success = true; } return success; }
From source file:ch.cyberduck.core.ftp.parser.OpensolarisFTPEntryParserTest.java
@Test public void testParse() throws Exception { FTPFile parsed; // #3689//ww w.jav a2 s .co 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.MicrosoftFTPEntryParserTest.java
@Test public void testParse() throws Exception { FTPFile parsed; // #3701/* w w w . ja va2s . 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: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 . c om*/ 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:com.esri.gpt.control.webharvest.client.waf.FtpFileIterator.java
/** * Creates new resource./*w ww .ja v a2 s . com*/ * @param file file * @return resource */ protected Resource newResource(FTPFile file) { if (file.isDirectory()) { return new FtpFolder(iterationContext, getFtpClient(), criteria, folder + "/" + file.getName()); } else if (file.isFile() && file.getName().toLowerCase().endsWith(".xml")) { if (criteria == null || criteria.getFromDate() == null || file.getTimestamp() == null || (criteria.getFromDate() != null && file.getTimestamp() != null && file.getTimestamp().after(criteria.getFromDate()))) { return new FtpFile(iterationContext, getFtpClient(), folder + "/" + file.getName()); } } return null; }
From source file:ch.cyberduck.core.ftp.parser.NTFTPEntryParserTest.java
@Test public void testDirectoryBeginningWithNumberFollowedBySpaces() throws Exception { FTPFile parsed = parser.parseFTPEntry("12-03-96 06:38AM <DIR> 123 xyz"); assertNotNull(parsed);/*from www. j av a 2s . co m*/ assertEquals("123 xyz", parsed.getName()); parsed = parser.parseFTPEntry("12-03-96 06:38AM <DIR> 123 abc xyz"); assertNotNull(parsed); assertEquals("123 abc xyz", parsed.getName()); }