List of usage examples for org.apache.commons.net.ftp FTPFile setTimestamp
public void setTimestamp(Calendar date)
From source file:at.beris.virtualfile.client.ftp.FtpClient.java
@Override public FTPFile getFileInfo(final String path) throws IOException { LOGGER.debug("getFileInfo (path: {})", path); return executionHandler(new Callable<FTPFile>() { @Override/*from w ww .j a v a2 s. c o m*/ public FTPFile call() throws Exception { if ("/".equals(path)) { FTPFile rootFile = new FTPFile(); rootFile.setName("/"); rootFile.setTimestamp(GregorianCalendar.getInstance()); return rootFile; } else { String lastPathPart = UrlUtils.getLastPathPart(path); String parentPath = UrlUtils.getParentPath(path); ftpClient.changeWorkingDirectory(parentPath); FTPFile[] ftpFiles = ftpClient.listFiles(); for (FTPFile ftpFile : ftpFiles) { if (ftpFile.getName().equals(lastPathPart)) { return ftpFile; } } return new FTPFile(); } } }); }
From source file:lucee.commons.io.res.type.ftp.FTPResource.java
@Override public boolean setLastModified(long time) { //if(isRoot()) return false; FTPResourceClient client = null;//w w w. j a v a 2s . c om try { provider.lock(this); client = provider.getClient(data); PageContext pc = ThreadLocalPageContext.get(); Calendar c = JREDateTimeUtil.getThreadCalendar(); if (pc != null) c.setTimeZone(pc.getTimeZone()); c.setTimeInMillis(time); FTPFile file = client.getFTPFile(this); if (file == null) return false; file.setTimestamp(c); client.unregisterFTPFile(this); return true; } catch (IOException e) { } finally { provider.returnClient(client); provider.unlock(this); } return false; }
From source file:com.ai.api.util.UnixFTPEntryParser.java
/** * Parses a line of a unix (standard) FTP server file listing and converts * it into a usable format in the form of an <code> FTPFile </code> * instance. If the file listing line doesn't describe a file, * <code> null </code> is returned, otherwise a <code> FTPFile </code> * instance representing the files in the directory is returned. * <p>/*from www. j ava 2 s . c o m*/ * @param entry A line of text from the file listing * @return An FTPFile instance corresponding to the supplied entry */ public FTPFile parseFTPEntry(String entry) { FTPFile file = new FTPFile(); file.setRawListing(entry); int type; boolean isDevice = false; if (matches(entry)) { String typeStr = group(1); String hardLinkCount = group(15); String usr = group(16); String grp = group(17); String filesize = group(18); String datestr = group(19) + " " + group(20); String name = group(21); String endtoken = group(22); try { //file.setTimestamp(super.parseTimestamp(datestr)); FTPTimestampParserImplExZH Zh2En = new FTPTimestampParserImplExZH(); file.setTimestamp(Zh2En.parseTimestamp(datestr)); } catch (ParseException e) { //logger.error(e, e); //return null; // this is a parsing failure too. //logger.info(entry+":??"); file.setTimestamp(Calendar.getInstance()); } // bcdlfmpSs- switch (typeStr.charAt(0)) { case 'd': type = FTPFile.DIRECTORY_TYPE; break; case 'l': type = FTPFile.SYMBOLIC_LINK_TYPE; break; case 'b': case 'c': isDevice = true; // break; - fall through case 'f': case '-': type = FTPFile.FILE_TYPE; break; default: type = FTPFile.UNKNOWN_TYPE; } file.setType(type); int g = 4; for (int access = 0; access < 3; access++, g += 4) { // Use != '-' to avoid having to check for suid and sticky bits file.setPermission(access, FTPFile.READ_PERMISSION, (!group(g).equals("-"))); file.setPermission(access, FTPFile.WRITE_PERMISSION, (!group(g + 1).equals("-"))); String execPerm = group(g + 2); if (!execPerm.equals("-") && !Character.isUpperCase(execPerm.charAt(0))) { file.setPermission(access, FTPFile.EXECUTE_PERMISSION, true); } else { file.setPermission(access, FTPFile.EXECUTE_PERMISSION, false); } } if (!isDevice) { try { file.setHardLinkCount(Integer.parseInt(hardLinkCount)); } catch (NumberFormatException e) { // intentionally do nothing } } file.setUser(usr); file.setGroup(grp); try { file.setSize(Long.parseLong(filesize)); } catch (NumberFormatException e) { // intentionally do nothing } if (null == endtoken) { file.setName(name); } else { // oddball cases like symbolic links, file names // with spaces in them. name += endtoken; if (type == FTPFile.SYMBOLIC_LINK_TYPE) { int end = name.indexOf(" -> "); // Give up if no link indicator is present if (end == -1) { file.setName(name); } else { file.setName(name.substring(0, end)); file.setLink(name.substring(end + 4)); } } else { file.setName(name); } } return file; } else { logger.info("matches(entry) failure:" + entry); } return null; }
From source file:org.springframework.integration.ftp.filters.FtpPersistentAcceptOnceFileListFilterTests.java
@Test public void testRollback() throws Exception { FtpPersistentAcceptOnceFileListFilter filter = new FtpPersistentAcceptOnceFileListFilter( new SimpleMetadataStore(), "rollback:"); FTPFile ftpFile1 = new FTPFile(); ftpFile1.setName("foo"); ftpFile1.setTimestamp(Calendar.getInstance()); FTPFile ftpFile2 = new FTPFile(); ftpFile2.setName("bar"); ftpFile2.setTimestamp(Calendar.getInstance()); FTPFile ftpFile3 = new FTPFile(); ftpFile3.setName("baz"); ftpFile3.setTimestamp(Calendar.getInstance()); FTPFile[] files = new FTPFile[] { ftpFile1, ftpFile2, ftpFile3 }; List<FTPFile> passed = filter.filterFiles(files); assertTrue(Arrays.equals(files, passed.toArray())); List<FTPFile> now = filter.filterFiles(files); assertEquals(0, now.size());/*w ww.j a v a 2 s .c o m*/ filter.rollback(passed.get(1), passed); now = filter.filterFiles(files); assertEquals(2, now.size()); assertEquals("bar", now.get(0).getName()); assertEquals("baz", now.get(1).getName()); now = filter.filterFiles(files); assertEquals(0, now.size()); filter.close(); }
From source file:org.springframework.integration.ftp.outbound.FtpServerOutboundTests.java
@Test public void testMgetRecursivePartial() throws Exception { Session<FTPFile> session = spyOnSession(); doAnswer(invocation -> {//from w w w . j a v a 2 s. c om FTPFile[] files = (FTPFile[]) invocation.callRealMethod(); // add an extra file where the get will fail files = Arrays.copyOf(files, files.length + 1); FTPFile bogusFile = new FTPFile(); bogusFile.setName("bogus.txt"); bogusFile.setTimestamp(Calendar.getInstance()); files[files.length - 1] = bogusFile; return files; }).when(session).list("ftpSource/subFtpSource/"); String dir = "ftpSource/"; try { this.inboundMGetRecursive.send(new GenericMessage<Object>(dir + "*")); fail("expected exception"); } catch (PartialSuccessException e) { assertEquals(4, e.getDerivedInput().size()); assertEquals(2, e.getPartialResults().size()); assertThat(e.getCause().getMessage(), containsString("/ftpSource/subFtpSource/bogus.txt: No such file or directory.")); } }