List of usage examples for org.apache.commons.vfs2.provider.ftp FtpFileSystem putClient
public void putClient(final FtpClient client)
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;/* ww w . j a v a 2 s. c o 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.streamsets.pipeline.stage.origin.remote.FTPRemoteDownloadSourceDelegate.java
private long getModTime(FileObject fileObject) throws FileSystemException { long modTime = fileObject.getContent().getLastModifiedTime(); if (supportsMDTM) { FtpClient ftpClient = null;/*from w ww . jav a 2s . c o m*/ FtpFileSystem ftpFileSystem = (FtpFileSystem) remoteDir.getFileSystem(); try { ftpClient = ftpFileSystem.getClient(); FTPClient rawFtpClient = (FTPClient) getFtpClient.invoke(ftpClient); String path = fileObject.getName().getPath(); if (conf.userDirIsRoot && path.startsWith("/")) { // Remove the leading slash to turn it into a proper relative path path = path.substring(1); } FTPFile ftpFile = rawFtpClient.mdtmFile(path); if (ftpFile != null) { modTime = ftpFile.getTimestamp().getTimeInMillis(); } } catch (Exception e) { LOG.trace("Ignoring Exception from MDTM command and falling back to basic timestamp", e); } finally { if (ftpClient != null) { ftpFileSystem.putClient(ftpClient); } } } return modTime; }