List of usage examples for org.apache.commons.net.ftp FTPCmd MDTM
FTPCmd MDTM
To view the source code for org.apache.commons.net.ftp FTPCmd MDTM.
Click Source Link
From source file:com.streamsets.pipeline.stage.origin.remote.FTPAndSSHDUnitTest.java
protected void setupFTPServer(String homeDir) throws Exception { fakeFtpServer = new SessionTrackingFakeFtpServer(); fakeFtpServer.setServerControlPort(0); fakeFtpServer.setSystemName(FTPClientConfig.SYST_UNIX); fakeFtpServer.setFileSystem(new UnixFakeFileSystem()); UserAccount userAccount = new UserAccount(TESTUSER, TESTPASS, homeDir); fakeFtpServer.addUserAccount(userAccount); fakeFtpServer.start();//from w w w . j a va 2 s . com port = fakeFtpServer.getServerControlPort(); populateFakeFileSystemFromReal(new File(homeDir)); // Add the missing FEAT and MDTM commands fakeFtpServer.setCommandHandler(FTPCmd.FEAT.getCommand(), new StaticReplyCommandHandler(211, "MDTM")); fakeFtpServer.setCommandHandler(FTPCmd.MDTM.getCommand(), new AbstractStubCommandHandler() { @Override protected void handleCommand(Command command, Session session, InvocationRecord invocationRecord) { String pathname = command.getOptionalString(0); if (!pathname.startsWith("/")) { pathname = homeDir + "/" + pathname; } invocationRecord.set(StatCommandHandler.PATHNAME_KEY, pathname); FileSystemEntry file = fakeFtpServer.getFileSystem().getEntry(pathname); if (file == null) { sendReply(session, 550, null, "No such file or directory.", null); } else { String time = MDTM_DATE_FORMAT.format(file.getLastModified()); sendReply(session, 213, null, time, null); } } }); }
From source file:com.streamsets.pipeline.stage.origin.remote.FTPRemoteDownloadSourceDelegate.java
private void setupModTime() { // The FTP protocol's default way to list files gives very inaccurate/ambiguous/inconsistent timestamps (e.g. it's // common for many FTP servers to drop the HH:mm on files older than 6 months). Some FTP servers support the // MDTM command, which returns an accurate/correct timestamp, but not all servers support it. Here, we'll check if // MDTM is supported so we can use it later to get proper timestamps. Unfortunately, VFS does not expose a nice way // to use MDTM or to even get to the underlying FTPClient (VFS-257). We have to use reflection. supportsMDTM = false;//from w w w.j av a 2 s. co m FtpClient ftpClient = null; FtpFileSystem ftpFileSystem = (FtpFileSystem) remoteDir.getFileSystem(); try { ftpClient = ftpFileSystem.getClient(); getFtpClient = ftpClient.getClass().getDeclaredMethod("getFtpClient"); getFtpClient.setAccessible(true); FTPClient rawFtpClient = (FTPClient) getFtpClient.invoke(ftpClient); rawFtpClient.features(); supportsMDTM = rawFtpClient.getReplyString().contains(FTPCmd.MDTM.getCommand()); } catch (Exception e) { LOG.trace("Ignoring Exception when determining MDTM support", e); } finally { if (ftpClient != null) { ftpFileSystem.putClient(ftpClient); } } LOG.info("Using MDTM for more accurate timestamps: {}", supportsMDTM); }
From source file:com.atomicleopard.thundr.ftp.commons.FTP.java
/** * @since 2.0 **/ public int mdtm(String file) throws IOException { return sendCommand(FTPCmd.MDTM, file); }