Package org.apache.sshd.sftp.client.fs
Class SftpFileSystemProvider
java.lang.Object
java.nio.file.spi.FileSystemProvider
org.apache.sshd.sftp.client.fs.SftpFileSystemProvider
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 Summary
FieldsModifier and TypeFieldDescriptionprivate final SshClient
private final SftpClientFactory
private final NavigableMap<String,
SftpFileSystem> protected final org.slf4j.Logger
static final Set<Class<? extends FileAttributeView>>
static final String
URI parameter that can be used to specify a special version selection.private final SftpVersionSelector
-
Constructor Summary
ConstructorsConstructorDescriptionSftpFileSystemProvider
(SshClient client) SftpFileSystemProvider
(SshClient client, SftpClientFactory factory, SftpVersionSelector selector) SftpFileSystemProvider
(SshClient client, SftpVersionSelector selector) SftpFileSystemProvider
(SftpVersionSelector selector) -
Method Summary
Modifier and TypeMethodDescriptionprotected int
attributesToPermissions
(Path path, Collection<PosixFilePermission> perms) void
checkAccess
(Path path, AccessMode... modes) void
copy
(Path source, Path target, CopyOption... options) void
createDirectory
(Path dir, FileAttribute<?>... attrs) static URI
createFileSystemURI
(String host, int port, String username, String password) static URI
void
createSymbolicLink
(Path link, Path target, FileAttribute<?>... attrs) void
static String
encodeCredentials
(String username, String password) final SshClient
<V extends FileAttributeView>
VgetFileAttributeView
(Path path, Class<V> type, LinkOption... options) getFileStore
(Path path) getFileSystem
(String id) getFileSystem
(URI uri) static String
getFileSystemIdentifier
(String host, int port, String username) static String
Uses the host, port and username to create a unique identifierstatic String
getFileSystemIdentifier
(ClientSession session) Uses the remote host address, port and current username to create a unique identifierstatic String
getOctalPermissions
(int perms) static String
static String
getRWXPermissions
(int perms) final SftpVersionSelector
boolean
boolean
isSameFile
(Path path1, Path path2) boolean
isSupportedFileAttributeView
(Path path, Class<? extends FileAttributeView> type) boolean
isSupportedFileAttributeView
(SftpFileSystem fs, Class<? extends FileAttributeView> type) void
move
(Path source, Path target, CopyOption... options) newByteChannel
(Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs) newDirectoryStream
(Path dir, DirectoryStream.Filter<? super Path> filter) newFileChannel
(Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs) newFileSystem
(URI uri, Map<String, ?> env) newFileSystem
(ClientSession session) newInputStream
(Path path, OpenOption... options) newOutputStream
(Path path, OpenOption... options) static MutableBasicCredentials
parseCredentials
(String userInfo) static MutableBasicCredentials
parseCredentials
(URI uri) Attempts to parse the user information from the URIparseURIParameters
(String params) parseURIParameters
(URI uri) static Set<PosixFilePermission>
permissionsToAttributes
(int perms) protected NavigableMap<String,
Object> readAclViewAttributes
(SftpPath path, String view, String attrs, LinkOption... options) <A extends BasicFileAttributes>
AreadAttributes
(Path path, Class<A> type, LinkOption... options) readAttributes
(Path path, String view, String attrs, LinkOption... options) readAttributes
(Path path, String attributes, LinkOption... options) readCustomViewAttributes
(SftpPath path, String view, String attrs, LinkOption... options) protected NavigableMap<String,
Object> readPosixViewAttributes
(SftpPath path, String view, String attrs, LinkOption... options) readRemoteAttributes
(SftpPath path, LinkOption... options) readSymbolicLink
(Path link) protected SftpVersionSelector
resolveSftpVersionSelector
(URI uri, SftpVersionSelector defaultSelector, PropertyResolver resolver) void
setAttribute
(Path path, String attribute, Object value, LinkOption... options) void
setAttribute
(Path path, String view, String attr, Object value, LinkOption... options) void
toSftpPath
(Path path) Methods inherited from class java.nio.file.spi.FileSystemProvider
createLink, deleteIfExists, installedProviders, newAsynchronousFileChannel, newFileSystem
-
Field Details
-
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:
-
UNIVERSAL_SUPPORTED_VIEWS
-
log
protected final org.slf4j.Logger log -
clientInstance
-
factory
-
versionSelector
-
fileSystems
-
fsSessionInitializer
-
-
Constructor Details
-
SftpFileSystemProvider
public SftpFileSystemProvider() -
SftpFileSystemProvider
-
SftpFileSystemProvider
- 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:
-
SftpFileSystemProvider
-
SftpFileSystemProvider
public SftpFileSystemProvider(SshClient client, SftpClientFactory factory, SftpVersionSelector selector)
-
-
Method Details
-
getScheme
- Specified by:
getScheme
in classFileSystemProvider
-
getSftpVersionSelector
-
getClientInstance
-
getSftpClientFactory
-
getSftpFileSystemClientSessionInitializer
-
setSftpFileSystemClientSessionInitializer
public void setSftpFileSystemClientSessionInitializer(SftpFileSystemClientSessionInitializer initializer) -
newFileSystem
- Specified by:
newFileSystem
in classFileSystemProvider
- Throws:
IOException
-
resolveSftpVersionSelector
protected SftpVersionSelector resolveSftpVersionSelector(URI uri, SftpVersionSelector defaultSelector, PropertyResolver resolver) -
resolveFileSystemParameters
-
parseCredentials
Attempts to parse the user information from the URI -
parseCredentials
-
parseURIParameters
-
parseURIParameters
-
newFileSystem
- Throws:
IOException
-
getFileSystem
- Specified by:
getFileSystem
in classFileSystemProvider
-
removeFileSystem
- Parameters:
id
- File system identifier - ignored ifnull
/empty- Returns:
- The removed
SftpFileSystem
-null
if no match
-
getFileSystem
- Parameters:
id
- File system identifier - ignored ifnull
/empty- Returns:
- The cached
SftpFileSystem
-null
if no match
-
getPath
- Specified by:
getPath
in classFileSystemProvider
-
newByteChannel
public FileChannel newByteChannel(Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException - Specified by:
newByteChannel
in classFileSystemProvider
- Throws:
IOException
-
newFileChannel
public FileChannel newFileChannel(Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException - Overrides:
newFileChannel
in classFileSystemProvider
- Throws:
IOException
-
newInputStream
- Overrides:
newInputStream
in classFileSystemProvider
- Throws:
IOException
-
newOutputStream
- Overrides:
newOutputStream
in classFileSystemProvider
- Throws:
IOException
-
newDirectoryStream
public DirectoryStream<Path> newDirectoryStream(Path dir, DirectoryStream.Filter<? super Path> filter) throws IOException - Specified by:
newDirectoryStream
in classFileSystemProvider
- Throws:
IOException
-
createDirectory
- Specified by:
createDirectory
in classFileSystemProvider
- Throws:
IOException
-
delete
- Specified by:
delete
in classFileSystemProvider
- Throws:
IOException
-
copy
- Specified by:
copy
in classFileSystemProvider
- Throws:
IOException
-
move
- Specified by:
move
in classFileSystemProvider
- Throws:
IOException
-
isSameFile
- Specified by:
isSameFile
in classFileSystemProvider
- Throws:
IOException
-
isHidden
- Specified by:
isHidden
in classFileSystemProvider
- Throws:
IOException
-
getFileStore
- Specified by:
getFileStore
in classFileSystemProvider
- Throws:
IOException
-
createSymbolicLink
public void createSymbolicLink(Path link, Path target, FileAttribute<?>... attrs) throws IOException - Overrides:
createSymbolicLink
in classFileSystemProvider
- Throws:
IOException
-
readSymbolicLink
- Overrides:
readSymbolicLink
in classFileSystemProvider
- Throws:
IOException
-
checkAccess
- Specified by:
checkAccess
in classFileSystemProvider
- Throws:
IOException
-
getFileAttributeView
public <V extends FileAttributeView> V getFileAttributeView(Path path, Class<V> type, LinkOption... options) - Specified by:
getFileAttributeView
in classFileSystemProvider
-
isSupportedFileAttributeView
-
isSupportedFileAttributeView
public boolean isSupportedFileAttributeView(SftpFileSystem fs, Class<? extends FileAttributeView> type) -
readAttributes
public <A extends BasicFileAttributes> A readAttributes(Path path, Class<A> type, LinkOption... options) throws IOException - Specified by:
readAttributes
in classFileSystemProvider
- Throws:
IOException
-
readAttributes
public Map<String,Object> readAttributes(Path path, String attributes, LinkOption... options) throws IOException - Specified by:
readAttributes
in classFileSystemProvider
- Throws:
IOException
-
readAttributes
public Map<String,Object> readAttributes(Path path, String view, String attrs, LinkOption... options) throws IOException - Throws:
IOException
-
readCustomViewAttributes
protected Map<String,Object> readCustomViewAttributes(SftpPath path, String view, String attrs, LinkOption... options) throws IOException - Throws:
IOException
-
readAclViewAttributes
protected NavigableMap<String,Object> readAclViewAttributes(SftpPath path, String view, String attrs, LinkOption... options) throws IOException - Throws:
IOException
-
readRemoteAttributes
public SftpClient.Attributes readRemoteAttributes(SftpPath path, LinkOption... options) throws IOException - Throws:
IOException
-
readPosixViewAttributes
protected NavigableMap<String,Object> readPosixViewAttributes(SftpPath path, String view, String attrs, LinkOption... options) throws IOException - Throws:
IOException
-
setAttribute
public void setAttribute(Path path, String attribute, Object value, LinkOption... options) throws IOException - Specified by:
setAttribute
in classFileSystemProvider
- Throws:
IOException
-
setAttribute
public void setAttribute(Path path, String view, String attr, Object value, LinkOption... options) throws IOException - Throws:
IOException
-
toSftpPath
-
attributesToPermissions
-
getRWXPermissions
-
getOctalPermissions
-
permissionsToAttributes
-
getOctalPermissions
-
getFileSystemIdentifier
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
Uses the remote host address, port and current username to create a unique identifier- Parameters:
session
- TheClientSession
- Returns:
- The unique identifier
- See Also:
-
getFileSystemIdentifier
-
createFileSystemURI
-
createFileSystemURI
-
encodeCredentials
-