Package org.apache.sshd.sftp.client.fs
Class SftpFileSystemProvider
- java.lang.Object
-
- java.nio.file.spi.FileSystemProvider
-
- org.apache.sshd.sftp.client.fs.SftpFileSystemProvider
-
public class SftpFileSystemProvider extends java.nio.file.spi.FileSystemProvider
A registeredFileSystemProvider
that registers the "sftp://" scheme so that URLs with this protocol are handled as remote SFTPPath
-s - e.g., "sftp://user:password@host/remote/file/path
"
-
-
Field Summary
Fields Modifier and Type Field Description private SshClient
clientInstance
private SftpErrorDataHandler
errorDataHandler
private SftpClientFactory
factory
private java.util.NavigableMap<java.lang.String,SftpFileSystem>
fileSystems
private SftpFileSystemClientSessionInitializer
fsSessionInitializer
protected org.slf4j.Logger
log
static java.util.Set<java.lang.Class<? extends java.nio.file.attribute.FileAttributeView>>
UNIVERSAL_SUPPORTED_VIEWS
static java.lang.String
VERSION_PARAM
URI parameter that can be used to specify a special version selection.private SftpVersionSelector
versionSelector
-
Constructor Summary
Constructors Constructor Description SftpFileSystemProvider()
SftpFileSystemProvider(SshClient client)
SftpFileSystemProvider(SshClient client, SftpClientFactory factory, SftpVersionSelector selector)
SftpFileSystemProvider(SshClient client, SftpClientFactory factory, SftpVersionSelector selector, SftpErrorDataHandler errorDataHandler)
SftpFileSystemProvider(SshClient client, SftpVersionSelector selector)
SftpFileSystemProvider(SshClient client, SftpVersionSelector selector, SftpErrorDataHandler errorDataHandler)
SftpFileSystemProvider(SftpVersionSelector selector)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected int
attributesToPermissions(java.nio.file.Path path, java.util.Collection<java.nio.file.attribute.PosixFilePermission> perms)
void
checkAccess(java.nio.file.Path path, java.nio.file.AccessMode... modes)
void
copy(java.nio.file.Path source, java.nio.file.Path target, java.nio.file.CopyOption... options)
void
createDirectory(java.nio.file.Path dir, java.nio.file.attribute.FileAttribute<?>... attrs)
static java.net.URI
createFileSystemURI(java.lang.String host, int port, java.lang.String username, java.lang.String password)
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)
void
createSymbolicLink(java.nio.file.Path link, java.nio.file.Path target, java.nio.file.attribute.FileAttribute<?>... attrs)
void
delete(java.nio.file.Path path)
static java.lang.String
encodeCredentials(java.lang.String username, java.lang.String password)
SshClient
getClientInstance()
<V extends java.nio.file.attribute.FileAttributeView>
VgetFileAttributeView(java.nio.file.Path path, java.lang.Class<V> type, java.nio.file.LinkOption... options)
java.nio.file.FileStore
getFileStore(java.nio.file.Path path)
SftpFileSystem
getFileSystem(java.lang.String id)
java.nio.file.FileSystem
getFileSystem(java.net.URI uri)
static java.lang.String
getFileSystemIdentifier(java.lang.String host, int port, java.lang.String username)
static java.lang.String
getFileSystemIdentifier(java.net.URI uri)
Uses the host, port and username to create a unique identifierstatic java.lang.String
getFileSystemIdentifier(ClientSession session)
Uses the remote host address, port and current username to create a unique identifierstatic java.lang.String
getOctalPermissions(int perms)
static java.lang.String
getOctalPermissions(java.util.Collection<java.nio.file.attribute.PosixFilePermission> perms)
java.nio.file.Path
getPath(java.net.URI uri)
static java.lang.String
getRWXPermissions(int perms)
java.lang.String
getScheme()
SftpClientFactory
getSftpClientFactory()
SftpErrorDataHandler
getSftpErrorDataHandler()
SftpFileSystemClientSessionInitializer
getSftpFileSystemClientSessionInitializer()
SftpVersionSelector
getSftpVersionSelector()
boolean
isHidden(java.nio.file.Path path)
boolean
isSameFile(java.nio.file.Path path1, java.nio.file.Path path2)
boolean
isSupportedFileAttributeView(java.nio.file.Path path, java.lang.Class<? extends java.nio.file.attribute.FileAttributeView> type)
boolean
isSupportedFileAttributeView(SftpFileSystem fs, java.lang.Class<? extends java.nio.file.attribute.FileAttributeView> type)
void
move(java.nio.file.Path source, java.nio.file.Path target, java.nio.file.CopyOption... options)
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)
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)
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)
SftpFileSystem
newFileSystem(java.net.URI uri, java.util.Map<java.lang.String,?> env)
SftpFileSystem
newFileSystem(ClientSession session)
java.io.InputStream
newInputStream(java.nio.file.Path path, java.nio.file.OpenOption... options)
java.io.OutputStream
newOutputStream(java.nio.file.Path path, java.nio.file.OpenOption... options)
static MutableBasicCredentials
parseCredentials(java.lang.String userInfo)
static MutableBasicCredentials
parseCredentials(java.net.URI uri)
Attempts to parse the user information from the URIstatic java.util.Map<java.lang.String,java.lang.Object>
parseURIParameters(java.lang.String params)
static java.util.Map<java.lang.String,java.lang.Object>
parseURIParameters(java.net.URI uri)
static java.util.Set<java.nio.file.attribute.PosixFilePermission>
permissionsToAttributes(int perms)
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)
<A extends java.nio.file.attribute.BasicFileAttributes>
AreadAttributes(java.nio.file.Path path, java.lang.Class<A> type, java.nio.file.LinkOption... options)
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)
java.util.Map<java.lang.String,java.lang.Object>
readAttributes(java.nio.file.Path path, java.lang.String attributes, java.nio.file.LinkOption... options)
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)
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)
SftpClient.Attributes
readRemoteAttributes(SftpPath path, java.nio.file.LinkOption... options)
java.nio.file.Path
readSymbolicLink(java.nio.file.Path link)
SftpFileSystem
removeFileSystem(java.lang.String id)
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)
protected SftpClient.Attributes
resolveRemoteFileAttributes(SftpPath path, java.nio.file.LinkOption... options)
protected SftpErrorDataHandler
resolveSftpErrorDataHandler(java.net.URI uri, SftpErrorDataHandler errorHandler, PropertyResolver resolver)
protected SftpVersionSelector
resolveSftpVersionSelector(java.net.URI uri, SftpVersionSelector defaultSelector, PropertyResolver resolver)
void
setAttribute(java.nio.file.Path path, java.lang.String attribute, java.lang.Object value, java.nio.file.LinkOption... options)
void
setAttribute(java.nio.file.Path path, java.lang.String view, java.lang.String attr, java.lang.Object value, java.nio.file.LinkOption... options)
void
setSftpFileSystemClientSessionInitializer(SftpFileSystemClientSessionInitializer initializer)
SftpPath
toSftpPath(java.nio.file.Path 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 clientmin
- select minimum available version for the clientcurrent
- whatever version is reported by the servernnn
- select only the specified versiona,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
-
factory
private final SftpClientFactory factory
-
versionSelector
private final SftpVersionSelector versionSelector
-
errorDataHandler
private final SftpErrorDataHandler errorDataHandler
-
fileSystems
private final java.util.NavigableMap<java.lang.String,SftpFileSystem> fileSystems
-
fsSessionInitializer
private SftpFileSystemClientSessionInitializer fsSessionInitializer
-
-
Constructor Detail
-
SftpFileSystemProvider
public SftpFileSystemProvider()
-
SftpFileSystemProvider
public SftpFileSystemProvider(SftpVersionSelector selector)
-
SftpFileSystemProvider
public SftpFileSystemProvider(SshClient client)
-
SftpFileSystemProvider
public SftpFileSystemProvider(SshClient client, SftpVersionSelector selector)
-
SftpFileSystemProvider
public SftpFileSystemProvider(SshClient client, SftpVersionSelector selector, SftpErrorDataHandler errorDataHandler)
-
SftpFileSystemProvider
public SftpFileSystemProvider(SshClient client, SftpClientFactory factory, SftpVersionSelector selector)
-
SftpFileSystemProvider
public SftpFileSystemProvider(SshClient client, SftpClientFactory factory, SftpVersionSelector selector, SftpErrorDataHandler errorDataHandler)
- Parameters:
client
- TheSshClient
to use - ifnull
then a default one will be setup and started. Otherwise, it is assumed that the client has already been startedfactory
- TheSftpClientFactory
to use to generate SFTP client instancesselector
- TheSftpVersionSelector
to use in order to negotiate the SFTP versionerrorDataHandler
- TheSftpErrorDataHandler
to handle incoming data through the error stream - ifnull
the data is silently ignored- See Also:
SshClient.setUpDefaultClient()
-
-
Method Detail
-
getScheme
public java.lang.String getScheme()
- Specified by:
getScheme
in classjava.nio.file.spi.FileSystemProvider
-
getSftpVersionSelector
public final SftpVersionSelector getSftpVersionSelector()
-
getSftpErrorDataHandler
public SftpErrorDataHandler getSftpErrorDataHandler()
-
getClientInstance
public final SshClient getClientInstance()
-
getSftpClientFactory
public SftpClientFactory getSftpClientFactory()
-
getSftpFileSystemClientSessionInitializer
public SftpFileSystemClientSessionInitializer getSftpFileSystemClientSessionInitializer()
-
setSftpFileSystemClientSessionInitializer
public void setSftpFileSystemClientSessionInitializer(SftpFileSystemClientSessionInitializer initializer)
-
newFileSystem
public SftpFileSystem newFileSystem(java.net.URI uri, java.util.Map<java.lang.String,?> env) throws java.io.IOException
- Specified by:
newFileSystem
in classjava.nio.file.spi.FileSystemProvider
- Throws:
java.io.IOException
-
resolveSftpVersionSelector
protected SftpVersionSelector resolveSftpVersionSelector(java.net.URI uri, SftpVersionSelector defaultSelector, PropertyResolver resolver)
-
resolveSftpErrorDataHandler
protected SftpErrorDataHandler resolveSftpErrorDataHandler(java.net.URI uri, SftpErrorDataHandler errorHandler, PropertyResolver resolver)
-
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
- TheURI
value - ignored ifnull
or does not contain anyuser info
.- Returns:
- The parsed credentials -
null
if none available
-
parseCredentials
public static MutableBasicCredentials parseCredentials(java.lang.String userInfo)
-
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 classjava.nio.file.spi.FileSystemProvider
-
removeFileSystem
public SftpFileSystem removeFileSystem(java.lang.String id)
- Parameters:
id
- File system identifier - ignored ifnull
/empty- Returns:
- The removed
SftpFileSystem
-null
if no match
-
getFileSystem
public SftpFileSystem getFileSystem(java.lang.String id)
- Parameters:
id
- File system identifier - ignored ifnull
/empty- Returns:
- The cached
SftpFileSystem
-null
if no match
-
getPath
public java.nio.file.Path getPath(java.net.URI uri)
- Specified by:
getPath
in classjava.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 classjava.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 classjava.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 classjava.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 classjava.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 classjava.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 classjava.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 classjava.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 classjava.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 classjava.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 classjava.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 classjava.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 classjava.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 classjava.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 classjava.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 classjava.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 classjava.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 classjava.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 classjava.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
-
resolveRemoteFileAttributes
protected SftpClient.Attributes resolveRemoteFileAttributes(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 classjava.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
- TheURI
- Note: not checked to make sure that the scheme issftp://
- Returns:
- The unique identifier
- See Also:
getFileSystemIdentifier(String, int, String)
-
getFileSystemIdentifier
public static java.lang.String getFileSystemIdentifier(ClientSession session)
Uses the remote host address, port and current username to create a unique identifier- Parameters:
session
- TheClientSession
- 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)
-
-