List of usage examples for org.apache.commons.net.ftp FTPFile getTimestamp
public Calendar getTimestamp()
From source file:biz.gabrys.lesscss.extended.compiler.source.FtpSource.java
private static Date getModificationDate(final FTPFile file) { if (file.getTimestamp() == null) { return new Date(); }//from w w w . j a v a2 s. co m return file.getTimestamp().getTime(); }
From source file:joshuatee.wx.UtilityFTP.java
public static String[] GetNidsArr(Context c, String url, String path, String frame_cnt_str) { int frame_cnt = Integer.parseInt(frame_cnt_str); String[] nids_arr = new String[frame_cnt]; try {//from w w w. j a v a 2 s.com FTPClient ftp = new FTPClient(); //String user = "ftp"; //String pass = "anonymous"; ftp.connect(url); if (!ftp.login("ftp", "anonymous")) { ftp.logout(); } ftp.setFileType(FTP.BINARY_FILE_TYPE); int reply = ftp.getReplyCode(); if (!FTPReply.isPositiveCompletion(reply)) { ftp.disconnect(); } ftp.enterLocalPassiveMode(); ftp.changeWorkingDirectory(path); //reply = ftp.getReplyCode(); FTPFile[] ftpFiles = ftp.listFiles(); //get newest .xml file name from ftp server java.util.Date lastMod = ftpFiles[0].getTimestamp().getTime(); FTPFile choice = ftpFiles[0]; for (FTPFile file : ftpFiles) { if (file.getTimestamp().getTime().after(lastMod) && !file.getName().equals("sn.last")) { choice = file; lastMod = file.getTimestamp().getTime(); } } int seq = Integer.parseInt(choice.getName().replace("sn.", "")); // was ALl int j = 0; int k = seq - frame_cnt + 1; for (j = 0; j < frame_cnt; j++) { // files range from 0000 to 0250, if num is negative add 251 int tmp_k = k; if (tmp_k < 0) tmp_k = tmp_k + 251; nids_arr[j] = "sn." + String.format("%4s", Integer.toString(tmp_k)).replace(' ', '0'); k++; } FileOutputStream fos; for (j = 0; j < frame_cnt; j++) { fos = c.openFileOutput(nids_arr[j], Context.MODE_PRIVATE); ftp.retrieveFile(nids_arr[j], fos); fos.close(); } ftp.logout(); ftp.disconnect(); } catch (Exception ex) { ex.printStackTrace(); } return nids_arr; }
From source file:lucel_updater.utils.LastModifiedComparator.java
public int compare(FTPFile f1, FTPFile f2) { return f1.getTimestamp().compareTo(f2.getTimestamp()); }
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 ww w . j av a 2 s .c o 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: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.j av a2s. co m fos.flush(); file.setLastModified(lastModified); success = true; } return success; }
From source file:ch.cyberduck.core.ftp.parser.NTFTPEntryParserTest.java
@Test public void testParseFieldsOnDirectory() throws Exception { FTPFile parsed = parser.parseFTPEntry("12-05-96 05:03PM <DIR> absoft2"); assertNotNull("Could not parse entry.", parsed); assertEquals("Thu Dec 05 17:03:00 1996", df.format(parsed.getTimestamp().getTime())); assertTrue(parsed.isDirectory());//from ww w . j a va2 s . c om assertEquals("absoft2", parsed.getName()); parsed = parser.parseFTPEntry("12-03-96 06:38AM <DIR> 123456"); assertNotNull("Could not parse entry.", parsed); assertTrue(parsed.isDirectory()); assertEquals("123456", parsed.getName()); }
From source file:ch.cyberduck.core.ftp.parser.NTFTPEntryParserTest.java
@Test public void testParseFieldsOnFile() throws Exception { FTPFile parsed = parser.parseFTPEntry("05-22-97 12:08AM 5000000000 AUTOEXEC.BAK"); assertNotNull("Could not parse entry.", parsed); assertEquals("Thu May 22 00:08:00 1997", df.format(parsed.getTimestamp().getTime())); assertTrue(parsed.isFile());/*from w w w . ja va2s . c o m*/ assertEquals("AUTOEXEC.BAK", parsed.getName()); assertEquals(5000000000l, parsed.getSize()); }
From source file:net.audumla.climate.bom.BOMSimpleClimateForcastObserver.java
protected String getLatestForcastFile() { BOMDataLoader loader = BOMDataLoader.instance(); Date time = new Date(0); String found = null;/* w w w. j a v a 2 s . co m*/ String filename = ""; for (String name : BOMForcastFiles) { try { filename = BOMDataLoader.BOMBaseFTPDir + BOMDataLoader.FWO + name; FTPFile file = loader.getFTPFile(BOMDataLoader.BOMFTP, filename); if (file != null) { if (file.getTimestamp().getTime().after(time)) { time = file.getTimestamp().getTime(); found = filename; } } else { LOG.error("Error locating file " + BOMDataLoader.BOMFTP + filename); } } catch (Exception ex) { LOG.error("Error locating file " + BOMDataLoader.BOMFTP + filename, ex); } } return filename; }
From source file:net.siegmar.japtproxy.fetcher.FetcherFtp.java
/** * {@inheritDoc}//from www .j a v a 2s . c o m */ @Override public FetchedResourceFtp fetch(final URL targetResource, final long lastModified, final String originalUserAgent) throws IOException, ResourceUnavailableException { final FTPClient ftpClient = new FTPClient(); ftpClient.setSoTimeout(socketTimeout); ftpClient.setDataTimeout(dataTimeout); try { final String host = targetResource.getHost(); final String resourceName = targetResource.getPath(); LOG.debug("Configured FetcherFtp: Host '{}', Resource '{}'", host, resourceName); ftpClient.connect(host); ftpClient.enterLocalPassiveMode(); if (!ftpClient.login("anonymous", "japt-proxy")) { throw new IOException("Can't login to FTP server"); } ftpClient.setFileType(FTP.BINARY_FILE_TYPE); final FTPFile[] files = ftpClient.listFiles(resourceName); if (files.length == 0) { throw new ResourceUnavailableException("Resource '" + resourceName + "' not found"); } if (files.length > 1) { throw new IOException("Multiple files found"); } final FTPFile file = files[0]; final FetchedResourceFtp fetchedResourceFtp = new FetchedResourceFtp(ftpClient, file); fetchedResourceFtp .setModified(lastModified == 0 || lastModified < file.getTimestamp().getTimeInMillis()); return fetchedResourceFtp; } catch (final IOException e) { // Closing only in case of an exception - otherwise closed by FetchedResourceFtp if (ftpClient.isConnected()) { ftpClient.disconnect(); } throw e; } }
From source file:ca.ualberta.physics.cssdp.file.remote.protocol.FtpConnection.java
@Override public List<RemoteFile> ls(String path) { logger.debug("Listing files at " + path); try {/*from w ww . j a v a 2s. c o m*/ ftpClient.enterLocalPassiveMode(); FTPFile[] files = ftpClient.listFiles(path); if (files == null || files.length == 0) { return new ArrayList<RemoteFile>(); } List<RemoteFile> list = new ArrayList<RemoteFile>(); for (FTPFile file : files) { String name = file.getName(); long size = file.getSize(); boolean isDir = file.isDirectory(); LocalDateTime modifiedTstamp = new LocalDateTime(file.getTimestamp()); RemoteFile remoteFile = new RemoteFile("ftp://" + getHostEntry().getHostname() + path + "/" + name, size, modifiedTstamp, isDir); list.add(remoteFile); } return list; } catch (SocketTimeoutException timeout) { throw new ProtocolException("Timedout listing " + path, true, timeout); } catch (IOException e) { throw new ProtocolException("Could not get file listing for " + path, false, e); } }