List of usage examples for org.apache.commons.net.ftp FTPFile getName
public String getName()
From source file:org.sofun.platform.opta.impl.OptaServiceImpl.java
@Override public void syncFLiveFeeds() throws OptaException { final String liveFeedPattern = "srml-.*-.*-f.*-matchresults.xml"; int processed = 0; final FTPClientWrapper opta = getFTPClientWrapper(); try {//from ww w .j ava2 s .c o m opta.connect(); final FTPFileFilter filter = new FTPFileFilterImpl(liveFeedPattern, this); for (FTPFile ftpFile : opta.getClient().listFiles(null, filter)) { if (processed > 50) { // batch to keep transactions small. // mostly an issue while bootstrapping new competitions with // lots of pending feeds to process. log.info("End of Football Live Feeds processing batch. Will resume in 5 minutes."); break; } File feed = getFileFromFTP(opta, ftpFile.getName()); F07Parser f7p = f7Sync(feed); if (f7p.getGame() != null) { log.info("Syncing file with name=" + ftpFile.getName()); setFileAsProcessed(ftpFile.getName(), ftpFile.getTimestamp().getTime()); processed += 1; } else { log.warn("Could not find game for live feed with name=" + ftpFile.getName()); } } } catch (IOException e) { throw new OptaException(e.getMessage()); } finally { opta.disconnect(); } }
From source file:org.sofun.platform.opta.impl.OptaServiceImpl.java
/** * Synchronize all RU feeds for a given competition's season (RU1, RU2 and * RU2)// w w w . ja va2s. c o m * * <p> * * This method is responsible for the actual update of feeds if they do * require it. * * @param competitionId: the competition ID * @param season: the season label. * @return the amount processed files. * @throws OptaException */ private int syncRUComp(String competitionId, String season) throws OptaException { final String ru1Pattern = String.format("ru1_compfixtures.(%s).(%s).*.xml", competitionId, season); final String ru2Pattern = String.format("ru2_tables.(%s).(%s).xml", competitionId, season); final String ru10Pattern = String.format("ru10_comp-(%s).xml", competitionId); int processed = 0; final FTPClientWrapper opta = getFTPClientWrapper(); try { opta.connect(); // RU1 first (order matters) FTPFileFilter filter = new FTPFileFilterImpl(ru1Pattern, this); for (FTPFile ftpFile : opta.getClient().listFiles(null, filter)) { File feed = getFileFromFTP(opta, ftpFile.getName()); ru1Sync(feed); log.info("Syncing file with name=" + ftpFile.getName()); setFileAsProcessed(ftpFile.getName(), ftpFile.getTimestamp().getTime()); processed += 1; if (processed >= 50) { // batch to keep transactions small. These feeds are rather // large. // mostly an issue while bootstrapping new competitions with // lots of pending feeds to process. break; } } // RU10 // Only one RU10 per competition filter = new FTPFileFilterImpl(ru10Pattern, this); for (FTPFile ftpFile : opta.getClient().listFiles(null, filter)) { File feed = getFileFromFTP(opta, ftpFile.getName()); ru10Sync(feed); log.info("Syncing file with name=" + ftpFile.getName()); setFileAsProcessed(ftpFile.getName(), ftpFile.getTimestamp().getTime()); processed += 1; } // RU2 // Only one RU2 per competition filter = new FTPFileFilterImpl(ru2Pattern, this); for (FTPFile ftpFile : opta.getClient().listFiles(null, filter)) { File feed = getFileFromFTP(opta, ftpFile.getName()); ru2Sync(feed); log.info("Syncing file with name=" + ftpFile.getName()); setFileAsProcessed(ftpFile.getName(), ftpFile.getTimestamp().getTime()); processed += 1; } } catch (IOException e) { throw new OptaException(e.getMessage()); } finally { opta.disconnect(); } return processed; }
From source file:org.sofun.platform.opta.impl.OptaServiceImpl.java
@Override public void syncRULiveFeeds() throws OptaException { final String liveFeedPattern = "ru6_wapresults.*.*.xml"; int processed = 0; final FTPClientWrapper opta = getFTPClientWrapper(); try {/* w ww. ja v a2 s . c o m*/ opta.connect(); final FTPFileFilter filter = new FTPFileFilterImpl(liveFeedPattern, this); for (FTPFile ftpFile : opta.getClient().listFiles(null, filter)) { if (processed > 50) { // batch to keep transactions small. // mostly an issue while bootstrapping new competitions with // lots of pending feeds to process. log.info("End of Rugby Live Feeds processing batch. Will resume in 5 minutes."); break; } File feed = getFileFromFTP(opta, ftpFile.getName()); RU6Parser ru6p = ru6Sync(feed); if (ru6p.getGame() != null) { log.info("Syncing file with name=" + ftpFile.getName()); setFileAsProcessed(ftpFile.getName(), ftpFile.getTimestamp().getTime()); processed += 1; } else { log.warn("Could not find game for live feed with name=" + ftpFile.getName()); } } } catch (IOException e) { throw new OptaException(e.getMessage()); } finally { opta.disconnect(); } }
From source file:org.sofun.platform.opta.impl.OptaServiceImpl.java
/** * /*from w ww .j av a2 s. c om*/ * @param season * @return * @throws OptaException */ private int syncFormula1Season(String season) throws OptaException { final String mr4Pattern = String.format("F1_STANDINGS_DRIVER_(%s).xml", season); final String mr5Pattern = String.format("F1_STANDINGS_TEAMS_(%s).xml", season); final String mr6Pattern = String.format("F1_CALENDAR_(%s).xml", season); final String mr2QualiPattern = "F1_QUALI_.*_NT.xml"; final String mr2FPPattern = "F1_FP.*_NT.xml"; final String mr1Pattern = "F1_RACE_.*_NT.xml"; int processed = 0; final FTPClientWrapper opta = getFTPClientWrapper(); try { opta.connect(); // MR6 first first (order matters) FTPFileFilter filter = new FTPFileFilterImpl(mr6Pattern, this); for (FTPFile ftpFile : opta.getClient().listFiles(null, filter)) { File feed = getFileFromFTP(opta, ftpFile.getName()); mr6Sync(feed); log.info("Syncing file with name=" + ftpFile.getName()); setFileAsProcessed(ftpFile.getName(), ftpFile.getTimestamp().getTime()); processed += 1; if (processed >= 50) { // batch to keep transactions small. These feeds are rather // large. // mostly an issue while bootstrapping new competitions with // lots of pending feeds to process. break; } } // MR5 filter = new FTPFileFilterImpl(mr5Pattern, this); for (FTPFile ftpFile : opta.getClient().listFiles(null, filter)) { File feed = getFileFromFTP(opta, ftpFile.getName()); mr5Sync(feed); log.info("Syncing file with name=" + ftpFile.getName()); setFileAsProcessed(ftpFile.getName(), ftpFile.getTimestamp().getTime()); } // MR4 filter = new FTPFileFilterImpl(mr4Pattern, this); for (FTPFile ftpFile : opta.getClient().listFiles(null, filter)) { File feed = getFileFromFTP(opta, ftpFile.getName()); mr4Sync(feed); log.info("Syncing file with name=" + ftpFile.getName()); setFileAsProcessed(ftpFile.getName(), ftpFile.getTimestamp().getTime()); } // MR2 filter = new FTPFileFilterImpl(mr2QualiPattern, this); for (FTPFile ftpFile : opta.getClient().listFiles(null, filter)) { File feed = getFileFromFTP(opta, ftpFile.getName()); mr2Sync(feed); log.info("Syncing file with name=" + ftpFile.getName()); setFileAsProcessed(ftpFile.getName(), ftpFile.getTimestamp().getTime()); } filter = new FTPFileFilterImpl(mr2FPPattern, this); for (FTPFile ftpFile : opta.getClient().listFiles(null, filter)) { File feed = getFileFromFTP(opta, ftpFile.getName()); mr2Sync(feed); log.info("Syncing file with name=" + ftpFile.getName()); setFileAsProcessed(ftpFile.getName(), ftpFile.getTimestamp().getTime()); } // MR1 filter = new FTPFileFilterImpl(mr1Pattern, this); for (FTPFile ftpFile : opta.getClient().listFiles(null, filter)) { File feed = getFileFromFTP(opta, ftpFile.getName()); mr1Sync(feed); log.info("Syncing file with name=" + ftpFile.getName()); setFileAsProcessed(ftpFile.getName(), ftpFile.getTimestamp().getTime()); } } catch (IOException e) { throw new OptaException(e.getMessage()); } finally { opta.disconnect(); } return processed; }
From source file:org.sofun.platform.opta.impl.OptaServiceImpl.java
@Override public void syncTennisLiveFeeds() throws OptaException { final String liveFeedPattern = "TAB7-.*.xml"; int processed = 0; final FTPClientWrapper opta = getFTPClientWrapper(); try {/* w ww . ja va2 s .c o m*/ opta.connect(); final FTPFileFilter filter = new FTPFileFilterImpl(liveFeedPattern, this); for (FTPFile ftpFile : opta.getClient().listFiles(null, filter)) { if (processed > 100) { // batch to keep transactions small. // mostly an issue while bootstrapping new competitions with // lots of pending feeds to process. log.info("End of Tennis Live Feeds processing batch. Will resume in 5 minutes."); break; } File feed = getFileFromFTP(opta, ftpFile.getName()); TAB7Parser tab7p = tab7Sync(feed); if (tab7p.getGame() != null) { log.info("Syncing file with name=" + ftpFile.getName()); setFileAsProcessed(ftpFile.getName(), ftpFile.getTimestamp().getTime()); processed += 1; } else { log.warn("Could not find game for live feed with name=" + ftpFile.getName()); } } } catch (IOException e) { throw new OptaException(e.getMessage()); } finally { opta.disconnect(); } }
From source file:org.sofun.platform.opta.impl.OptaServiceImpl.java
/** * Synchronize all Cycling feeds for a given competition's season (CY1, * CY40)/*from w w w. j a v a 2s . c o m*/ * * <p> * * This method is responsible for the actual update of feeds if they do * require it. * * @param competitionId: the competition ID * @param season: the season label. * @return the amount processed files. * @throws OptaException */ private int syncCyclingComp(String competitionId, String season) throws OptaException { final String cy1 = "CNC_" + competitionId + ".Xml"; final String cy40 = "CMP_" + competitionId + ".Xml"; final String csf = "CSF_" + competitionId + "_.*.Xml"; int processed = 0; final FTPClientWrapper opta = getFTPClientWrapper(); try { opta.connect(); // Processing CY1 (order matters for first run) OptaProcessedFeed pfeed = getProcessedFeedFor(cy1); FTPFile ftpFile = null; boolean process = false; FTPFile[] ftpfiles; try { ftpfiles = opta.getClient().listFiles(cy1); } catch (IOException e) { throw new OptaException(e.getMessage()); } if (ftpfiles.length == 1) { ftpFile = ftpfiles[0]; } if (pfeed == null) { process = true; } else { if (ftpFile != null) { final Date formerFeedTimestamp = pfeed.getTimestamp(); final Date newFeedTimestamp = ftpFile.getTimestamp().getTime(); if (newFeedTimestamp == null || newFeedTimestamp.compareTo(formerFeedTimestamp) > 0) { process = true; } else { log.debug("Feed has not changed. No need to reprocess feed=" + cy1); } } else { log.warn("Feed with name=" + cy1 + " cannot be found"); } } if (process && ftpFile != null) { File feed = getFileFromFTP(opta, cy1); if (feed != null) { log.info("Syncing file with name=" + cy1); cy1Sync(feed); setFileAsProcessed(cy1, ftpFile.getTimestamp().getTime()); processed += 1; } else { log.warn("Feed not available:" + cy1); } } // Processing CY40 pfeed = getProcessedFeedFor(cy40); ftpFile = null; process = false; try { ftpfiles = opta.getClient().listFiles(cy40); } catch (IOException e) { throw new OptaException(e.getMessage()); } if (ftpfiles.length == 1) { ftpFile = ftpfiles[0]; } if (pfeed == null) { process = true; } else { if (ftpFile != null) { final Date formerFeedTimestamp = pfeed.getTimestamp(); final Date newFeedTimestamp = ftpFile.getTimestamp().getTime(); if (newFeedTimestamp == null || newFeedTimestamp.compareTo(formerFeedTimestamp) > 0) { process = true; } else { log.debug("Feed has not changed. No need to reprocess feed=" + cy40); } } else { log.warn("Feed with name=" + cy40 + " cannot be found"); } } if (process && ftpFile != null) { File feed = getFileFromFTP(opta, cy40); if (feed != null) { log.info("Syncing file with name=" + cy40); cy40sync(feed); setFileAsProcessed(cy40, ftpFile.getTimestamp().getTime()); processed += 1; } else { log.warn("Feed not available:" + cy40); } } // Processing CSF FTPFileFilter filter = new FTPFileFilterImpl(csf, this); for (FTPFile ftpf : opta.getClient().listFiles(null, filter)) { File feed = getFileFromFTP(opta, ftpf.getName()); cyCSFCync(feed); log.info("Syncing file with name=" + ftpf.getName()); setFileAsProcessed(ftpf.getName(), ftpf.getTimestamp().getTime()); processed += 1; } } catch (IOException e) { throw new OptaException(e.getMessage()); } finally { opta.disconnect(); } return processed; }
From source file:org.soitoolkit.commons.mule.ftp.FtpUtil.java
/** * Deletes a directory with all its files and sub-directories. * // w w w . j a v a2 s. c o m * @param ftpClient * @param path * @throws IOException */ static public void recursiveDeleteDirectory(FTPClient ftpClient, String path) throws IOException { logger.info("Delete directory: {}", path); FTPFile[] ftpFiles = ftpClient.listFiles(path); logger.debug("Number of files that will be deleted: {}", ftpFiles.length); for (FTPFile ftpFile : ftpFiles) { String filename = path + "/" + ftpFile.getName(); if (ftpFile.getType() == FTPFile.FILE_TYPE) { boolean deleted = ftpClient.deleteFile(filename); logger.debug("Deleted {}? {}", filename, deleted); } else { recursiveDeleteDirectory(ftpClient, filename); } } boolean dirDeleted = ftpClient.deleteFile(path); logger.debug("Directory {} deleted: {}", path, dirDeleted); }
From source file:org.spka.cursus.publish.website.ftp.ListFiles.java
public void from(FTPClient ftp) throws IOException { for (FTPFile file : ftp.listFiles(Constants.RESULTS_DIR, FILES_ONLY)) { files.put(Constants.RESULTS_DIR + "/" + file.getName(), null); }/* ww w . j ava 2 s.c om*/ }
From source file:org.springframework.integration.ftp.filters.FtpPersistentAcceptOnceFileListFilter.java
@Override protected String fileName(FTPFile file) { return file.getName(); }
From source file:org.springframework.integration.ftp.filters.FtpRegexPatternFileListFilter.java
@Override protected String getFilename(FTPFile file) { return (file != null) ? file.getName() : null; }