Class SftpFileSystemWindowsProvider

  • All Implemented Interfaces:
    Closeable, AutoCloseable, org.apache.commons.vfs2.provider.FileProvider, org.apache.commons.vfs2.provider.VfsComponent

    public class SftpFileSystemWindowsProvider
    extends org.apache.commons.vfs2.provider.sftp.SftpFileProvider
    This class serves two main purposes.
    1. To provide a correct way of running sftp commands on Windows server. Current implementation of commons-vfs calls id -G or id -u, which is incorrect for Windows.
    2. To provide a way to release sftp connections, when we're done. commons-vfs says we do not close fileSystemManager until application shutdown (see VFS-454). Thus, we need to close the connections.
      There is AbstractFileProvider.freeUnusedResources(), which we can use to achieve this. But, unfortunately, original SftpFileSystem only releases them when all file objects it's associated with are garbage collected. This is too restrictive and inconvenient. Here we make the sftp file system object releasable when there are open file objects, we only need i/o streams to be closed.
      This is pretty safe to do. Even a file object would want to open a stream once again (currently wouldn't), the file system object re-creates session and opens a new connection.
    This provider replaces SftpFileProvider in FileSystemManager (see overridden providers.xml). And then used to spawn SftpFileSystemWindows and SftpFileObjectWithWindowsSupport.
    • Field Summary

      • Fields inherited from class org.apache.commons.vfs2.provider.sftp.SftpFileProvider

        ATTR_USER_INFO, AUTHENTICATOR_TYPES, capabilities
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected org.apache.commons.vfs2.FileSystem doCreateFileSystem​(org.apache.commons.vfs2.FileName name, org.apache.commons.vfs2.FileSystemOptions fileSystemOptions)  
      • Methods inherited from class org.apache.commons.vfs2.provider.sftp.SftpFileProvider

        getCapabilities, getConfigBuilder
      • Methods inherited from class org.apache.commons.vfs2.provider.AbstractOriginatingFileProvider

        findFile, findFile, getFileSystem
      • Methods inherited from class org.apache.commons.vfs2.provider.AbstractFileProvider

        addFileSystem, close, closeFileSystem, createFileSystem, findFileSystem, freeUnusedResources, getFileNameParser, parseUri, setFileNameParser
      • Methods inherited from class org.apache.commons.vfs2.provider.AbstractVfsContainer

        addComponent, removeComponent
      • Methods inherited from class org.apache.commons.vfs2.provider.AbstractVfsComponent

        getContext, getLogger, init, setContext, setLogger
    • Constructor Detail

      • SftpFileSystemWindowsProvider

        public SftpFileSystemWindowsProvider()
    • Method Detail

      • doCreateFileSystem

        protected org.apache.commons.vfs2.FileSystem doCreateFileSystem​(org.apache.commons.vfs2.FileName name,
                                                                        org.apache.commons.vfs2.FileSystemOptions fileSystemOptions)
                                                                 throws org.apache.commons.vfs2.FileSystemException
        Overrides:
        doCreateFileSystem in class org.apache.commons.vfs2.provider.sftp.SftpFileProvider
        Throws:
        org.apache.commons.vfs2.FileSystemException