Class SftpFileSystemProvider


  • public class SftpFileSystemProvider
    extends java.nio.file.spi.FileSystemProvider
    A registered FileSystemProvider that registers the "sftp://" scheme so that URLs with this protocol are handled as remote SFTP Path-s - e.g., "sftp://user:password@host/remote/file/path"
    • Field Detail

      • VERSION_PARAM

        public static final java.lang.String VERSION_PARAM

        URI parameter that can be used to specify a special version selection. Options are:

        • max - select maximum available version for the client
        • min - select minimum available version for the client
        • current - whatever version is reported by the server
        • nnn - select only the specified version
        • a,b,c - select one of the specified versions (if available) in preference order
        See Also:
        Constant Field Values
      • UNIVERSAL_SUPPORTED_VIEWS

        public static final java.util.Set<java.lang.Class<? extends java.nio.file.attribute.FileAttributeView>> UNIVERSAL_SUPPORTED_VIEWS
      • log

        protected final org.slf4j.Logger log
      • clientInstance

        private final SshClient clientInstance
      • fileSystems

        private final java.util.NavigableMap<java.lang.String,​SftpFileSystem> fileSystems
    • Method Detail

      • getScheme

        public java.lang.String getScheme()
        Specified by:
        getScheme in class java.nio.file.spi.FileSystemProvider
      • getClientInstance

        public final SshClient getClientInstance()
      • newFileSystem

        public SftpFileSystem newFileSystem​(java.net.URI uri,
                                            java.util.Map<java.lang.String,​?> env)
                                     throws java.io.IOException
        Specified by:
        newFileSystem in class java.nio.file.spi.FileSystemProvider
        Throws:
        java.io.IOException
      • resolveFileSystemParameters

        public static java.util.Map<java.lang.String,​java.lang.Object> resolveFileSystemParameters​(java.util.Map<java.lang.String,​?> env,
                                                                                                         java.util.Map<java.lang.String,​java.lang.Object> uriParams)
      • parseCredentials

        public static MutableBasicCredentials parseCredentials​(java.net.URI uri)
        Attempts to parse the user information from the URI
        Parameters:
        uri - The URI value - ignored if null or does not contain any user info.
        Returns:
        The parsed credentials - null if none available
      • parseURIParameters

        public static java.util.Map<java.lang.String,​java.lang.Object> parseURIParameters​(java.net.URI uri)
      • parseURIParameters

        public static java.util.Map<java.lang.String,​java.lang.Object> parseURIParameters​(java.lang.String params)
      • newFileSystem

        public SftpFileSystem newFileSystem​(ClientSession session)
                                     throws java.io.IOException
        Throws:
        java.io.IOException
      • getFileSystem

        public java.nio.file.FileSystem getFileSystem​(java.net.URI uri)
        Specified by:
        getFileSystem in class java.nio.file.spi.FileSystemProvider
      • removeFileSystem

        public SftpFileSystem removeFileSystem​(java.lang.String id)
        Parameters:
        id - File system identifier - ignored if null/empty
        Returns:
        The removed SftpFileSystem - null if no match
      • getFileSystem

        public SftpFileSystem getFileSystem​(java.lang.String id)
        Parameters:
        id - File system identifier - ignored if null/empty
        Returns:
        The cached SftpFileSystem - null if no match
      • getPath

        public java.nio.file.Path getPath​(java.net.URI uri)
        Specified by:
        getPath in class java.nio.file.spi.FileSystemProvider
      • newByteChannel

        public java.nio.channels.FileChannel newByteChannel​(java.nio.file.Path path,
                                                            java.util.Set<? extends java.nio.file.OpenOption> options,
                                                            java.nio.file.attribute.FileAttribute<?>... attrs)
                                                     throws java.io.IOException
        Specified by:
        newByteChannel in class java.nio.file.spi.FileSystemProvider
        Throws:
        java.io.IOException
      • newFileChannel

        public java.nio.channels.FileChannel newFileChannel​(java.nio.file.Path path,
                                                            java.util.Set<? extends java.nio.file.OpenOption> options,
                                                            java.nio.file.attribute.FileAttribute<?>... attrs)
                                                     throws java.io.IOException
        Overrides:
        newFileChannel in class java.nio.file.spi.FileSystemProvider
        Throws:
        java.io.IOException
      • newInputStream

        public java.io.InputStream newInputStream​(java.nio.file.Path path,
                                                  java.nio.file.OpenOption... options)
                                           throws java.io.IOException
        Overrides:
        newInputStream in class java.nio.file.spi.FileSystemProvider
        Throws:
        java.io.IOException
      • newOutputStream

        public java.io.OutputStream newOutputStream​(java.nio.file.Path path,
                                                    java.nio.file.OpenOption... options)
                                             throws java.io.IOException
        Overrides:
        newOutputStream in class java.nio.file.spi.FileSystemProvider
        Throws:
        java.io.IOException
      • newDirectoryStream

        public java.nio.file.DirectoryStream<java.nio.file.Path> newDirectoryStream​(java.nio.file.Path dir,
                                                                                    java.nio.file.DirectoryStream.Filter<? super java.nio.file.Path> filter)
                                                                             throws java.io.IOException
        Specified by:
        newDirectoryStream in class java.nio.file.spi.FileSystemProvider
        Throws:
        java.io.IOException
      • createDirectory

        public void createDirectory​(java.nio.file.Path dir,
                                    java.nio.file.attribute.FileAttribute<?>... attrs)
                             throws java.io.IOException
        Specified by:
        createDirectory in class java.nio.file.spi.FileSystemProvider
        Throws:
        java.io.IOException
      • delete

        public void delete​(java.nio.file.Path path)
                    throws java.io.IOException
        Specified by:
        delete in class java.nio.file.spi.FileSystemProvider
        Throws:
        java.io.IOException
      • copy

        public void copy​(java.nio.file.Path source,
                         java.nio.file.Path target,
                         java.nio.file.CopyOption... options)
                  throws java.io.IOException
        Specified by:
        copy in class java.nio.file.spi.FileSystemProvider
        Throws:
        java.io.IOException
      • move

        public void move​(java.nio.file.Path source,
                         java.nio.file.Path target,
                         java.nio.file.CopyOption... options)
                  throws java.io.IOException
        Specified by:
        move in class java.nio.file.spi.FileSystemProvider
        Throws:
        java.io.IOException
      • isSameFile

        public boolean isSameFile​(java.nio.file.Path path1,
                                  java.nio.file.Path path2)
                           throws java.io.IOException
        Specified by:
        isSameFile in class java.nio.file.spi.FileSystemProvider
        Throws:
        java.io.IOException
      • isHidden

        public boolean isHidden​(java.nio.file.Path path)
                         throws java.io.IOException
        Specified by:
        isHidden in class java.nio.file.spi.FileSystemProvider
        Throws:
        java.io.IOException
      • getFileStore

        public java.nio.file.FileStore getFileStore​(java.nio.file.Path path)
                                             throws java.io.IOException
        Specified by:
        getFileStore in class java.nio.file.spi.FileSystemProvider
        Throws:
        java.io.IOException
      • createSymbolicLink

        public void createSymbolicLink​(java.nio.file.Path link,
                                       java.nio.file.Path target,
                                       java.nio.file.attribute.FileAttribute<?>... attrs)
                                throws java.io.IOException
        Overrides:
        createSymbolicLink in class java.nio.file.spi.FileSystemProvider
        Throws:
        java.io.IOException
      • readSymbolicLink

        public java.nio.file.Path readSymbolicLink​(java.nio.file.Path link)
                                            throws java.io.IOException
        Overrides:
        readSymbolicLink in class java.nio.file.spi.FileSystemProvider
        Throws:
        java.io.IOException
      • checkAccess

        public void checkAccess​(java.nio.file.Path path,
                                java.nio.file.AccessMode... modes)
                         throws java.io.IOException
        Specified by:
        checkAccess in class java.nio.file.spi.FileSystemProvider
        Throws:
        java.io.IOException
      • getFileAttributeView

        public <V extends java.nio.file.attribute.FileAttributeView> V getFileAttributeView​(java.nio.file.Path path,
                                                                                            java.lang.Class<V> type,
                                                                                            java.nio.file.LinkOption... options)
        Specified by:
        getFileAttributeView in class java.nio.file.spi.FileSystemProvider
      • isSupportedFileAttributeView

        public boolean isSupportedFileAttributeView​(java.nio.file.Path path,
                                                    java.lang.Class<? extends java.nio.file.attribute.FileAttributeView> type)
      • isSupportedFileAttributeView

        public boolean isSupportedFileAttributeView​(SftpFileSystem fs,
                                                    java.lang.Class<? extends java.nio.file.attribute.FileAttributeView> type)
      • readAttributes

        public <A extends java.nio.file.attribute.BasicFileAttributes> A readAttributes​(java.nio.file.Path path,
                                                                                        java.lang.Class<A> type,
                                                                                        java.nio.file.LinkOption... options)
                                                                                 throws java.io.IOException
        Specified by:
        readAttributes in class java.nio.file.spi.FileSystemProvider
        Throws:
        java.io.IOException
      • readAttributes

        public java.util.Map<java.lang.String,​java.lang.Object> readAttributes​(java.nio.file.Path path,
                                                                                     java.lang.String attributes,
                                                                                     java.nio.file.LinkOption... options)
                                                                              throws java.io.IOException
        Specified by:
        readAttributes in class java.nio.file.spi.FileSystemProvider
        Throws:
        java.io.IOException
      • readAttributes

        public java.util.Map<java.lang.String,​java.lang.Object> readAttributes​(java.nio.file.Path path,
                                                                                     java.lang.String view,
                                                                                     java.lang.String attrs,
                                                                                     java.nio.file.LinkOption... options)
                                                                              throws java.io.IOException
        Throws:
        java.io.IOException
      • readCustomViewAttributes

        protected java.util.Map<java.lang.String,​java.lang.Object> readCustomViewAttributes​(SftpPath path,
                                                                                                  java.lang.String view,
                                                                                                  java.lang.String attrs,
                                                                                                  java.nio.file.LinkOption... options)
                                                                                           throws java.io.IOException
        Throws:
        java.io.IOException
      • readAclViewAttributes

        protected java.util.NavigableMap<java.lang.String,​java.lang.Object> readAclViewAttributes​(SftpPath path,
                                                                                                        java.lang.String view,
                                                                                                        java.lang.String attrs,
                                                                                                        java.nio.file.LinkOption... options)
                                                                                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • readRemoteAttributes

        public SftpClient.Attributes readRemoteAttributes​(SftpPath path,
                                                          java.nio.file.LinkOption... options)
                                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • readPosixViewAttributes

        protected java.util.NavigableMap<java.lang.String,​java.lang.Object> readPosixViewAttributes​(SftpPath path,
                                                                                                          java.lang.String view,
                                                                                                          java.lang.String attrs,
                                                                                                          java.nio.file.LinkOption... options)
                                                                                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • setAttribute

        public void setAttribute​(java.nio.file.Path path,
                                 java.lang.String attribute,
                                 java.lang.Object value,
                                 java.nio.file.LinkOption... options)
                          throws java.io.IOException
        Specified by:
        setAttribute in class java.nio.file.spi.FileSystemProvider
        Throws:
        java.io.IOException
      • setAttribute

        public void setAttribute​(java.nio.file.Path path,
                                 java.lang.String view,
                                 java.lang.String attr,
                                 java.lang.Object value,
                                 java.nio.file.LinkOption... options)
                          throws java.io.IOException
        Throws:
        java.io.IOException
      • toSftpPath

        public SftpPath toSftpPath​(java.nio.file.Path path)
      • attributesToPermissions

        protected int attributesToPermissions​(java.nio.file.Path path,
                                              java.util.Collection<java.nio.file.attribute.PosixFilePermission> perms)
      • getRWXPermissions

        public static java.lang.String getRWXPermissions​(int perms)
      • getOctalPermissions

        public static java.lang.String getOctalPermissions​(int perms)
      • permissionsToAttributes

        public static java.util.Set<java.nio.file.attribute.PosixFilePermission> permissionsToAttributes​(int perms)
      • getOctalPermissions

        public static java.lang.String getOctalPermissions​(java.util.Collection<java.nio.file.attribute.PosixFilePermission> perms)
      • getFileSystemIdentifier

        public static java.lang.String getFileSystemIdentifier​(java.net.URI uri)
        Uses the host, port and username to create a unique identifier
        Parameters:
        uri - The URI - Note: not checked to make sure that the scheme is sftp://
        Returns:
        The unique identifier
        See Also:
        getFileSystemIdentifier(String, int, String)
      • getFileSystemIdentifier

        public static java.lang.String getFileSystemIdentifier​(java.lang.String host,
                                                               int port,
                                                               java.lang.String username)
      • createFileSystemURI

        public static java.net.URI createFileSystemURI​(java.lang.String host,
                                                       int port,
                                                       java.lang.String username,
                                                       java.lang.String password)
      • createFileSystemURI

        public static java.net.URI createFileSystemURI​(java.lang.String host,
                                                       int port,
                                                       java.lang.String username,
                                                       java.lang.String password,
                                                       java.util.Map<java.lang.String,​?> params)
      • encodeCredentials

        public static java.lang.String encodeCredentials​(java.lang.String username,
                                                         java.lang.String password)