Class SftpFileSystemProvider
- java.lang.Object
-
- java.nio.file.spi.FileSystemProvider
-
- org.apache.sshd.client.subsystem.sftp.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 static java.lang.String
AUTH_TIME_PROP_NAME
private SshClient
clientInstance
static java.lang.String
CONNECT_TIME_PROP_NAME
static long
DEFAULT_AUTH_TIME
static long
DEFAULT_CONNECT_TIME
static java.nio.charset.Charset
DEFAULT_NAME_DECODER_CHARSET
static int
DEFAULT_READ_BUFFER_SIZE
static int
DEFAULT_WRITE_BUFFER_SIZE
private SftpClientFactory
factory
private java.util.NavigableMap<java.lang.String,SftpFileSystem>
fileSystems
private SftpFileSystemClientSessionInitializer
fsSessionInitializer
protected org.slf4j.Logger
log
static java.lang.String
NAME_DECORDER_CHARSET_PROP_NAME
static java.lang.String
READ_BUFFER_PROP_NAME
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
static java.lang.String
WRITE_BUFFER_PROP_NAME
-
Constructor Summary
Constructors Constructor Description SftpFileSystemProvider()
SftpFileSystemProvider(SshClient client)
SftpFileSystemProvider(SshClient client, SftpClientFactory factory, SftpVersionSelector selector)
SftpFileSystemProvider(SshClient client, SftpVersionSelector selector)
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()
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)
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 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
-
READ_BUFFER_PROP_NAME
public static final java.lang.String READ_BUFFER_PROP_NAME
- See Also:
- Constant Field Values
-
DEFAULT_READ_BUFFER_SIZE
public static final int DEFAULT_READ_BUFFER_SIZE
- See Also:
- Constant Field Values
-
WRITE_BUFFER_PROP_NAME
public static final java.lang.String WRITE_BUFFER_PROP_NAME
- See Also:
- Constant Field Values
-
DEFAULT_WRITE_BUFFER_SIZE
public static final int DEFAULT_WRITE_BUFFER_SIZE
- See Also:
- Constant Field Values
-
CONNECT_TIME_PROP_NAME
public static final java.lang.String CONNECT_TIME_PROP_NAME
- See Also:
- Constant Field Values
-
DEFAULT_CONNECT_TIME
public static final long DEFAULT_CONNECT_TIME
-
AUTH_TIME_PROP_NAME
public static final java.lang.String AUTH_TIME_PROP_NAME
- See Also:
- Constant Field Values
-
DEFAULT_AUTH_TIME
public static final long DEFAULT_AUTH_TIME
-
NAME_DECORDER_CHARSET_PROP_NAME
public static final java.lang.String NAME_DECORDER_CHARSET_PROP_NAME
- See Also:
- Constant Field Values
-
DEFAULT_NAME_DECODER_CHARSET
public static final java.nio.charset.Charset DEFAULT_NAME_DECODER_CHARSET
-
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
-
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)
- 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 started- See Also:
SshClient.setUpDefaultClient()
-
SftpFileSystemProvider
public SftpFileSystemProvider(SshClient client, SftpVersionSelector selector)
-
SftpFileSystemProvider
public SftpFileSystemProvider(SshClient client, SftpClientFactory factory, SftpVersionSelector selector)
-
-
Method Detail
-
getScheme
public java.lang.String getScheme()
- Specified by:
getScheme
in classjava.nio.file.spi.FileSystemProvider
-
getSftpVersionSelector
public final SftpVersionSelector getSftpVersionSelector()
-
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)
-
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
-
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
-
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)
-
-