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"-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classA session provider that automatically creates a new session if the current one is no longer open (or if there isn't one yet). -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final SshClientprivate final SftpErrorDataHandlerprivate final SftpClientFactoryprivate final NavigableMap<String, SftpFileSystem> protected final org.slf4j.Loggerstatic final Set<Class<? extends FileAttributeView>> static final StringURI 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, SftpClientFactory factory, SftpVersionSelector selector, SftpErrorDataHandler errorDataHandler) SftpFileSystemProvider(SshClient client, SftpVersionSelector selector) SftpFileSystemProvider(SshClient client, SftpVersionSelector selector, SftpErrorDataHandler errorDataHandler) SftpFileSystemProvider(SftpVersionSelector selector) -
Method Summary
Modifier and TypeMethodDescriptionprotected intattributesToPermissions(Path path, Collection<PosixFilePermission> perms) voidcheckAccess(Path path, AccessMode... modes) voidcopy(Path source, Path target, CopyOption... options) voidcreateDirectory(Path dir, FileAttribute<?>... attrs) static URIcreateFileSystemURI(String host, int port, String username, String password) static URIvoidcreateSymbolicLink(Path link, Path target, FileAttribute<?>... attrs) voidstatic StringencodeCredentials(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 StringgetFileSystemIdentifier(String host, int port, String username) static StringUses the host, port and username to create a unique identifierstatic StringgetFileSystemIdentifier(ClientSession session) Uses the remote host address, port and current username to create a unique identifierstatic StringgetOctalPermissions(int perms) static Stringstatic StringgetRWXPermissions(int perms) final SftpVersionSelectorbooleanbooleanisSameFile(Path path1, Path path2) booleanisSupportedFileAttributeView(Path path, Class<? extends FileAttributeView> type) booleanisSupportedFileAttributeView(SftpFileSystem fs, Class<? extends FileAttributeView> type) voidmove(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 MutableBasicCredentialsparseCredentials(String userInfo) static MutableBasicCredentialsparseCredentials(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 SftpClient.AttributesresolveRemoteFileAttributes(SftpPath path, LinkOption... options) protected SftpErrorDataHandlerresolveSftpErrorDataHandler(URI uri, SftpErrorDataHandler errorHandler, PropertyResolver resolver) protected SftpVersionSelectorresolveSftpVersionSelector(URI uri, SftpVersionSelector defaultSelector, PropertyResolver resolver) voidsetAttribute(Path path, String attribute, Object value, LinkOption... options) voidsetAttribute(Path path, String view, String attr, Object value, LinkOption... options) voidtoSftpPath(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
-
errorDataHandler
-
fileSystems
-
fsSessionInitializer
-
-
Constructor Details
-
SftpFileSystemProvider
public SftpFileSystemProvider() -
SftpFileSystemProvider
-
SftpFileSystemProvider
-
SftpFileSystemProvider
-
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- TheSshClientto use - ifnullthen a default one will be setup and started. Otherwise, it is assumed that the client has already been startedfactory- TheSftpClientFactoryto use to generate SFTP client instancesselector- TheSftpVersionSelectorto use in order to negotiate the SFTP versionerrorDataHandler- TheSftpErrorDataHandlerto handle incoming data through the error stream - ifnullthe data is silently ignored- See Also:
-
-
Method Details
-
getScheme
- Specified by:
getSchemein classFileSystemProvider
-
getSftpVersionSelector
-
getSftpErrorDataHandler
-
getClientInstance
-
getSftpClientFactory
-
getSftpFileSystemClientSessionInitializer
-
setSftpFileSystemClientSessionInitializer
public void setSftpFileSystemClientSessionInitializer(SftpFileSystemClientSessionInitializer initializer) -
newFileSystem
- Specified by:
newFileSystemin classFileSystemProvider- Throws:
IOException
-
resolveSftpVersionSelector
protected SftpVersionSelector resolveSftpVersionSelector(URI uri, SftpVersionSelector defaultSelector, PropertyResolver resolver) -
resolveSftpErrorDataHandler
protected SftpErrorDataHandler resolveSftpErrorDataHandler(URI uri, SftpErrorDataHandler errorHandler, PropertyResolver resolver) -
resolveFileSystemParameters
-
parseCredentials
Attempts to parse the user information from the URI -
parseCredentials
-
parseURIParameters
-
parseURIParameters
-
newFileSystem
- Throws:
IOException
-
getFileSystem
- Specified by:
getFileSystemin classFileSystemProvider
-
removeFileSystem
- Parameters:
id- File system identifier - ignored ifnull/empty- Returns:
- The removed
SftpFileSystem-nullif no match
-
getFileSystem
- Parameters:
id- File system identifier - ignored ifnull/empty- Returns:
- The cached
SftpFileSystem-nullif no match
-
getPath
- Specified by:
getPathin classFileSystemProvider
-
newByteChannel
public FileChannel newByteChannel(Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException - Specified by:
newByteChannelin classFileSystemProvider- Throws:
IOException
-
newFileChannel
public FileChannel newFileChannel(Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException - Overrides:
newFileChannelin classFileSystemProvider- Throws:
IOException
-
newInputStream
- Overrides:
newInputStreamin classFileSystemProvider- Throws:
IOException
-
newOutputStream
- Overrides:
newOutputStreamin classFileSystemProvider- Throws:
IOException
-
newDirectoryStream
public DirectoryStream<Path> newDirectoryStream(Path dir, DirectoryStream.Filter<? super Path> filter) throws IOException - Specified by:
newDirectoryStreamin classFileSystemProvider- Throws:
IOException
-
createDirectory
- Specified by:
createDirectoryin classFileSystemProvider- Throws:
IOException
-
delete
- Specified by:
deletein classFileSystemProvider- Throws:
IOException
-
copy
- Specified by:
copyin classFileSystemProvider- Throws:
IOException
-
move
- Specified by:
movein classFileSystemProvider- Throws:
IOException
-
isSameFile
- Specified by:
isSameFilein classFileSystemProvider- Throws:
IOException
-
isHidden
- Specified by:
isHiddenin classFileSystemProvider- Throws:
IOException
-
getFileStore
- Specified by:
getFileStorein classFileSystemProvider- Throws:
IOException
-
createSymbolicLink
public void createSymbolicLink(Path link, Path target, FileAttribute<?>... attrs) throws IOException - Overrides:
createSymbolicLinkin classFileSystemProvider- Throws:
IOException
-
readSymbolicLink
- Overrides:
readSymbolicLinkin classFileSystemProvider- Throws:
IOException
-
checkAccess
- Specified by:
checkAccessin classFileSystemProvider- Throws:
IOException
-
getFileAttributeView
public <V extends FileAttributeView> V getFileAttributeView(Path path, Class<V> type, LinkOption... options) - Specified by:
getFileAttributeViewin 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:
readAttributesin classFileSystemProvider- Throws:
IOException
-
readAttributes
public Map<String,Object> readAttributes(Path path, String attributes, LinkOption... options) throws IOException - Specified by:
readAttributesin 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
-
resolveRemoteFileAttributes
protected SftpClient.Attributes resolveRemoteFileAttributes(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:
setAttributein 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
-