List of usage examples for org.apache.commons.net.ftp FTPFile isFile
public boolean isFile()
From source file:com.claim.controller.FileTransferController.java
public void readFilesFromServer(String targetDirectory) { FTPClient ftpClient = new FTPClient(); try {//from w w w . ja v a2s .c o m FtpProperties properties = new ResourcesProperties().loadFTPProperties(); ftpClient.connect(properties.getFtp_server(), properties.getFtp_port()); ftpClient.login(properties.getFtp_username(), properties.getFtp_password()); ftpClient.enterLocalPassiveMode(); ftpClient.setFileType(FTP.BINARY_FILE_TYPE); //FTP_REMOTE_HOME = ftpClient.printWorkingDirectory(); FTPFile[] ftpFiles = ftpClient.listFiles(); if (ftpFiles != null && ftpFiles.length > 0) { //loop thru files for (FTPFile file : ftpFiles) { if (!file.isFile()) { continue; } System.out.println("File is " + file.getName()); //get output stream OutputStream output; //output = new FileOutputStream(FTP_REMOTE_HOME + "/" + file.getName()); output = new FileOutputStream(file.getName()); //get the file from the remote system ftpClient.retrieveFile(file.getName(), output); //close output stream output.close(); //delete the file //ftpClient.deleteFile(file.getName()); } } } catch (Exception e) { e.printStackTrace(); } finally { try { if (ftpClient != null) { ftpClient.logout(); ftpClient.disconnect(); } } catch (IOException ex) { Logger.getLogger(FileTransferController.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:de.quadrillenschule.azocamsyncd.ftpservice.FTPConnection.java
public LinkedList<AZoFTPFile> discoverRemoteFiles(String root, boolean includeDirs) throws IOException { LinkedList<AZoFTPFile> retval = new LinkedList(); for (FTPFile f : ftpclient.listFiles(root)) { AZoFTPFile af = new AZoFTPFile(f, root); if (f.isFile() && isPicture(af) && !retval.contains(af)) { retval.add(af);/*from w w w. j av a 2s . c o m*/ } if (f.isDirectory()) { if (includeDirs) { retval.add(af); } retval.addAll(discoverRemoteFiles(root + f.getName() + "/", includeDirs)); } } return retval; }
From source file:ch.cyberduck.core.ftp.parser.UnixFTPEntryParserTest.java
@Test public void testCurrentYear() { FTPFileEntryParser parser = new FTPParserSelector().getParser("UNIX"); FTPFile parsed; parsed = parser.parseFTPEntry("-rw-r--r-- 1 20708 205 194 Oct 17 14:40 D3I0_805.fixlist"); assertNotNull(parsed);/*from w w w . j a va 2 s.c o m*/ assertTrue(parsed.isFile()); assertNotNull(parsed.getTimestamp()); assertEquals(Calendar.OCTOBER, parsed.getTimestamp().get(Calendar.MONTH)); assertEquals(17, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH)); assertEquals(14, parsed.getTimestamp().get(Calendar.HOUR_OF_DAY)); assertEquals(40, parsed.getTimestamp().get(Calendar.MINUTE)); }
From source file:ch.cyberduck.core.ftp.parser.UnixFTPEntryParserTest.java
/** * http://trac.cyberduck.ch/ticket/1076/*from w ww .j a v a 2 s . co m*/ * * @ */ @Test public void testSizeWithIndicator() { FTPFileEntryParser parser = new FTPParserSelector().getParser("UNIX"); FTPFile parsed; parsed = parser.parseFTPEntry("-rw-rw-rw- 1 ftp operator 9.0M Mar 22 17:44 Cyberduck-2.7.3.dmg"); assertNotNull(parsed); assertTrue(parsed.isFile()); assertEquals("Cyberduck-2.7.3.dmg", parsed.getName()); assertEquals((long) (9.0 * 1048576), parsed.getSize()); assertEquals(parsed.getUser(), "ftp"); assertEquals(parsed.getGroup(), "operator"); assertNotNull(parsed.getTimestamp()); assertEquals(Calendar.MARCH, parsed.getTimestamp().get(Calendar.MONTH)); assertEquals(22, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH)); parsed = parser.parseFTPEntry("-rw-rw-rw- 1 ftp operator 61.8M Mar 7 18:42 GC Wayfinding pics.zip "); assertNotNull(parsed); assertTrue(parsed.isFile()); assertEquals((long) (61.8 * 1048576), parsed.getSize()); assertEquals("ftp", parsed.getUser()); assertEquals("operator", parsed.getGroup()); assertNotNull(parsed.getTimestamp()); assertEquals(Calendar.MARCH, parsed.getTimestamp().get(Calendar.MONTH)); assertEquals(7, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH)); parsed = parser.parseFTPEntry("-rw-rw-rw- 1 ftp operator 172.4k Mar 7 16:01 HEALY071.TXT "); assertNotNull(parsed); assertTrue(parsed.isFile()); assertEquals((long) (172.4 * 1024), parsed.getSize()); assertEquals(parsed.getUser(), "ftp"); assertEquals(parsed.getGroup(), "operator"); assertNotNull(parsed.getTimestamp()); assertEquals(Calendar.MARCH, parsed.getTimestamp().get(Calendar.MONTH)); assertEquals(7, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH)); }
From source file:ch.cyberduck.core.ftp.parser.UnixFTPEntryParserTest.java
/** * http://trac.cyberduck.ch/ticket/143/*ww w .jav a 2 s. c o m*/ */ @Test public void testLeadingWhitespace() { FTPFileEntryParser parser = new FTPParserSelector().getParser("UNIX"); FTPFile parsed; parsed = parser.parseFTPEntry("-rw-r--r-- 1 20708 205 3553312 Feb 18 2005 D3I0_515.fmr"); assertNotNull(parsed); assertTrue(parsed.isFile()); assertEquals("D3I0_515.fmr", parsed.getName()); assertEquals("20708", parsed.getUser()); assertEquals("205", parsed.getGroup()); assertNotNull(parsed.getTimestamp()); assertEquals(Calendar.FEBRUARY, parsed.getTimestamp().get(Calendar.MONTH)); assertEquals(18, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH)); assertEquals(2005, parsed.getTimestamp().get(Calendar.YEAR)); parsed = parser.parseFTPEntry("drwxr-sr-x 14 17037 209 4096 Oct 6 2000 v3r7"); assertNotNull(parsed); assertTrue(parsed.isDirectory()); assertEquals("v3r7", parsed.getName()); assertEquals("17037", parsed.getUser()); assertEquals("209", parsed.getGroup()); assertNotNull(parsed.getTimestamp()); assertEquals(Calendar.OCTOBER, parsed.getTimestamp().get(Calendar.MONTH)); assertEquals(6, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH)); assertEquals(2000, parsed.getTimestamp().get(Calendar.YEAR)); // #2895 parsed = parser.parseFTPEntry("-rwx------ 1 user group 38635 Jul 13 2006 users.xml"); assertNotNull(parsed); assertEquals(FTPFile.FILE_TYPE, parsed.getType()); assertEquals("users.xml", parsed.getName()); assertEquals("user", parsed.getUser()); assertEquals("group", parsed.getGroup()); assertNotNull(parsed.getTimestamp()); assertEquals(Calendar.JULY, parsed.getTimestamp().get(Calendar.MONTH)); assertEquals(13, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH)); assertEquals(2006, parsed.getTimestamp().get(Calendar.YEAR)); }
From source file:lucee.commons.io.res.type.ftp.FTPResource.java
@Override public boolean isFile() { if (isRoot()) return false; try {/*from w w w . j ava 2 s . c o m*/ provider.read(this); } catch (IOException e1) { return false; } FTPResourceClient client = null; InputStream is = null; try { client = provider.getClient(data); FTPFile file = client.getFTPFile(this); if (file != null) { return file.isFile(); } return false; //String pathname = getInnerPath(); //return (is=client.retrieveFileStream(pathname))!=null; } catch (IOException e) { return false; } finally { IOUtil.closeEL(is); provider.returnClient(client); } }
From source file:com.connection.factory.FtpConnectionApacheLib.java
@Override public List<RemoteFileObject> readAllFilesWalkinPath(String remotePath) { List<RemoteFileObject> willReturnObject = new ArrayList<>(); Queue<RemoteFileObject> directorylist = new LinkedBlockingQueue<>(); RemoteFileObject object = null;//from w ww .j a v a 2 s.c om object = new FtpApacheFileObject(FileInfoEnum.DIRECTORY); object.setDirectPath(remotePath); directorylist.add(object); try { while (!directorylist.isEmpty()) { object = directorylist.poll(); FTPFile[] fileListTemp = _ftpObj.listFiles(object.getPath()); for (FTPFile each : fileListTemp) { RemoteFileObject objectTemp = null; if (each.isDirectory()) { objectTemp = new FtpApacheFileObject(FileInfoEnum.DIRECTORY); objectTemp.setFileName(each.getName()); objectTemp.setAbsolutePath(object.getPath()); directorylist.add(objectTemp); } else if (each.isFile()) { objectTemp = new FtpApacheFileObject(FileInfoEnum.FILE); objectTemp.setFileName(each.getName()); objectTemp.setAbsolutePath(object.getPath()); objectTemp.setFileSize(each.getSize()); objectTemp.setFileType(); objectTemp.setDate(each.getTimestamp().getTime()); willReturnObject.add(objectTemp); } } object = null; fileListTemp = null; } } catch (IOException ex) { return null; } catch (ConnectionException ex) { } return willReturnObject; }
From source file:com.connection.factory.FtpConnectionApacheLib.java
@Override public void readAllFilesWalkingPathWithListener(FileListener listener, String remotePath) { // List<RemoteFileObject> willReturnObject = new ArrayList<>(); Queue<RemoteFileObject> directorylist = new LinkedBlockingQueue<>(); RemoteFileObject object = null;//from w ww. j av a 2 s .co m object = new FtpApacheFileObject(FileInfoEnum.DIRECTORY); object.setDirectPath(remotePath); directorylist.add(object); try { while (!directorylist.isEmpty()) { object = directorylist.poll(); FTPFile[] fileListTemp = _ftpObj.listFiles(object.getPath()); for (FTPFile each : fileListTemp) { RemoteFileObject objectTemp = null; if (each.isDirectory()) { objectTemp = new FtpApacheFileObject(FileInfoEnum.DIRECTORY); objectTemp.setFileName(each.getName()); objectTemp.setAbsolutePath(object.getPath()); directorylist.add(objectTemp); } else if (each.isFile()) { objectTemp = new FtpApacheFileObject(FileInfoEnum.FILE); objectTemp.setFileName(each.getName()); objectTemp.setAbsolutePath(object.getPath()); objectTemp.setFileSize(each.getSize()); objectTemp.setFileType(); objectTemp.setDate(each.getTimestamp().getTime()); listener.handleRemoteFile(object); } } object = null; fileListTemp = null; } } catch (IOException | ConnectionException ex) { // return null; } // return willReturnObject; // return willReturnObject; }
From source file:com.moosemorals.mediabrowser.FtpScanner.java
private void scrapeFTP() throws IOException { synchronized (ftp) { connect();//from w w w. j a v a 2s . c o m List<PVRFolder> queue = new LinkedList<>(); queue.add((PVRFolder) pvr.getRoot()); int total = 0; int checked = 0; while (!queue.isEmpty() && !ftpThread.isInterrupted()) { PVRFolder directory = queue.remove(0); if (!ftp.changeWorkingDirectory(FTP_ROOT + directory.getRemotePath())) { throw new IOException("Can't change FTP directory to " + FTP_ROOT + directory.getRemotePath()); } FTPFile[] fileList = ftp.listFiles(); total += fileList.length; for (FTPFile f : fileList) { if (f.getName().equals(".") || f.getName().equals("..")) { // skip entries for this directory and parent directory total -= 1; continue; } if (f.isDirectory()) { PVRFolder next = pvr.addFolder(directory, f.getName()); next.setFtpScanned(true); pvr.updateItem(next); queue.add(next); } else if (f.isFile() && f.getName().endsWith(".ts")) { PVRFile file = pvr.addFile(directory, f.getName()); file.setSize(f.getSize()); updateFromHMT(file); pvr.updateItem(file); } checked += 1; notifyScanListeners(DeviceListener.ScanType.ftp, total, checked); } } disconnect(); } }
From source file:lucee.runtime.tag.Ftp.java
/** * check if a file exists or not//www . j a v a2 s.com * @return FTPCLient * @throws IOException * @throws PageException */ private FTPClient actionExistsFile() throws PageException, IOException { required("remotefile", remotefile); FTPClient client = getClient(); FTPFile file = existsFile(client, remotefile, true); Struct cfftp = writeCfftp(client); cfftp.setEL(RETURN_VALUE, Caster.toBoolean(file != null && file.isFile())); cfftp.setEL(SUCCEEDED, Boolean.TRUE); stoponerror = false; return client; }