public class SftpFileSystemProvider
extends java.nio.file.spi.FileSystemProvider
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
"Modifier and Type | Field and Description |
---|---|
private SshClient |
clientInstance |
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 and Description |
---|
SftpFileSystemProvider() |
SftpFileSystemProvider(SftpVersionSelector selector) |
SftpFileSystemProvider(SshClient client) |
SftpFileSystemProvider(SshClient client,
SftpClientFactory factory,
SftpVersionSelector selector) |
SftpFileSystemProvider(SshClient client,
SftpVersionSelector selector) |
Modifier and Type | Method and 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> |
getFileAttributeView(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(ClientSession session)
Uses the remote host address, port and current username to create a unique identifier
|
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 identifier
|
static java.lang.String |
getOctalPermissions(java.util.Collection<java.nio.file.attribute.PosixFilePermission> perms) |
static java.lang.String |
getOctalPermissions(int 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(ClientSession session) |
SftpFileSystem |
newFileSystem(java.net.URI uri,
java.util.Map<java.lang.String,?> env) |
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 URI
|
static 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> |
readAttributes(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 attributes,
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) |
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) |
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 orderpublic static final java.util.Set<java.lang.Class<? extends java.nio.file.attribute.FileAttributeView>> UNIVERSAL_SUPPORTED_VIEWS
protected final org.slf4j.Logger log
private final SshClient clientInstance
private final SftpClientFactory factory
private final SftpVersionSelector versionSelector
private final java.util.NavigableMap<java.lang.String,SftpFileSystem> fileSystems
private SftpFileSystemClientSessionInitializer fsSessionInitializer
public SftpFileSystemProvider()
public SftpFileSystemProvider(SftpVersionSelector selector)
public SftpFileSystemProvider(SshClient client)
client
- The SshClient
to use - if null
then a default one will be setup and started.
Otherwise, it is assumed that the client has already been startedSshClient.setUpDefaultClient()
public SftpFileSystemProvider(SshClient client, SftpVersionSelector selector)
public SftpFileSystemProvider(SshClient client, SftpClientFactory factory, SftpVersionSelector selector)
public java.lang.String getScheme()
getScheme
in class java.nio.file.spi.FileSystemProvider
public final SftpVersionSelector getSftpVersionSelector()
public final SshClient getClientInstance()
public SftpClientFactory getSftpClientFactory()
public SftpFileSystemClientSessionInitializer getSftpFileSystemClientSessionInitializer()
public void setSftpFileSystemClientSessionInitializer(SftpFileSystemClientSessionInitializer initializer)
public SftpFileSystem newFileSystem(java.net.URI uri, java.util.Map<java.lang.String,?> env) throws java.io.IOException
newFileSystem
in class java.nio.file.spi.FileSystemProvider
java.io.IOException
protected SftpVersionSelector resolveSftpVersionSelector(java.net.URI uri, SftpVersionSelector defaultSelector, PropertyResolver resolver)
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)
public static MutableBasicCredentials parseCredentials(java.net.URI uri)
uri
- The URI
value - ignored if null
or does not contain any user
info
.null
if none availablepublic static MutableBasicCredentials parseCredentials(java.lang.String userInfo)
public static java.util.Map<java.lang.String,java.lang.Object> parseURIParameters(java.net.URI uri)
public static java.util.Map<java.lang.String,java.lang.Object> parseURIParameters(java.lang.String params)
public SftpFileSystem newFileSystem(ClientSession session) throws java.io.IOException
java.io.IOException
public java.nio.file.FileSystem getFileSystem(java.net.URI uri)
getFileSystem
in class java.nio.file.spi.FileSystemProvider
public SftpFileSystem removeFileSystem(java.lang.String id)
id
- File system identifier - ignored if null
/emptySftpFileSystem
- null
if no matchpublic SftpFileSystem getFileSystem(java.lang.String id)
id
- File system identifier - ignored if null
/emptySftpFileSystem
- null
if no matchpublic java.nio.file.Path getPath(java.net.URI uri)
getPath
in class java.nio.file.spi.FileSystemProvider
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
newByteChannel
in class java.nio.file.spi.FileSystemProvider
java.io.IOException
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
newFileChannel
in class java.nio.file.spi.FileSystemProvider
java.io.IOException
public java.io.InputStream newInputStream(java.nio.file.Path path, java.nio.file.OpenOption... options) throws java.io.IOException
newInputStream
in class java.nio.file.spi.FileSystemProvider
java.io.IOException
public java.io.OutputStream newOutputStream(java.nio.file.Path path, java.nio.file.OpenOption... options) throws java.io.IOException
newOutputStream
in class java.nio.file.spi.FileSystemProvider
java.io.IOException
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
newDirectoryStream
in class java.nio.file.spi.FileSystemProvider
java.io.IOException
public void createDirectory(java.nio.file.Path dir, java.nio.file.attribute.FileAttribute<?>... attrs) throws java.io.IOException
createDirectory
in class java.nio.file.spi.FileSystemProvider
java.io.IOException
public void delete(java.nio.file.Path path) throws java.io.IOException
delete
in class java.nio.file.spi.FileSystemProvider
java.io.IOException
public void copy(java.nio.file.Path source, java.nio.file.Path target, java.nio.file.CopyOption... options) throws java.io.IOException
copy
in class java.nio.file.spi.FileSystemProvider
java.io.IOException
public void move(java.nio.file.Path source, java.nio.file.Path target, java.nio.file.CopyOption... options) throws java.io.IOException
move
in class java.nio.file.spi.FileSystemProvider
java.io.IOException
public boolean isSameFile(java.nio.file.Path path1, java.nio.file.Path path2) throws java.io.IOException
isSameFile
in class java.nio.file.spi.FileSystemProvider
java.io.IOException
public boolean isHidden(java.nio.file.Path path) throws java.io.IOException
isHidden
in class java.nio.file.spi.FileSystemProvider
java.io.IOException
public java.nio.file.FileStore getFileStore(java.nio.file.Path path) throws java.io.IOException
getFileStore
in class java.nio.file.spi.FileSystemProvider
java.io.IOException
public void createSymbolicLink(java.nio.file.Path link, java.nio.file.Path target, java.nio.file.attribute.FileAttribute<?>... attrs) throws java.io.IOException
createSymbolicLink
in class java.nio.file.spi.FileSystemProvider
java.io.IOException
public java.nio.file.Path readSymbolicLink(java.nio.file.Path link) throws java.io.IOException
readSymbolicLink
in class java.nio.file.spi.FileSystemProvider
java.io.IOException
public void checkAccess(java.nio.file.Path path, java.nio.file.AccessMode... modes) throws java.io.IOException
checkAccess
in class java.nio.file.spi.FileSystemProvider
java.io.IOException
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)
getFileAttributeView
in class java.nio.file.spi.FileSystemProvider
public boolean isSupportedFileAttributeView(java.nio.file.Path path, java.lang.Class<? extends java.nio.file.attribute.FileAttributeView> type)
public boolean isSupportedFileAttributeView(SftpFileSystem fs, java.lang.Class<? extends java.nio.file.attribute.FileAttributeView> type)
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
readAttributes
in class java.nio.file.spi.FileSystemProvider
java.io.IOException
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
readAttributes
in class java.nio.file.spi.FileSystemProvider
java.io.IOException
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
java.io.IOException
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
java.io.IOException
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
java.io.IOException
public SftpClient.Attributes readRemoteAttributes(SftpPath path, java.nio.file.LinkOption... options) throws java.io.IOException
java.io.IOException
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
java.io.IOException
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
setAttribute
in class java.nio.file.spi.FileSystemProvider
java.io.IOException
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
java.io.IOException
public SftpPath toSftpPath(java.nio.file.Path path)
protected int attributesToPermissions(java.nio.file.Path path, java.util.Collection<java.nio.file.attribute.PosixFilePermission> perms)
public static java.lang.String getRWXPermissions(int perms)
public static java.lang.String getOctalPermissions(int perms)
public static java.util.Set<java.nio.file.attribute.PosixFilePermission> permissionsToAttributes(int perms)
public static java.lang.String getOctalPermissions(java.util.Collection<java.nio.file.attribute.PosixFilePermission> perms)
public static java.lang.String getFileSystemIdentifier(java.net.URI uri)
uri
- The URI
- Note: not checked to make sure that the scheme is sftp://
getFileSystemIdentifier(String, int, String)
public static java.lang.String getFileSystemIdentifier(ClientSession session)
session
- The ClientSession
getFileSystemIdentifier(String, int, String)
public static java.lang.String getFileSystemIdentifier(java.lang.String host, int port, java.lang.String username)
public static java.net.URI createFileSystemURI(java.lang.String host, int port, java.lang.String username, java.lang.String password)
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)
public static java.lang.String encodeCredentials(java.lang.String username, java.lang.String password)