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.FileSystemProviderA registeredFileSystemProviderthat 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 SshClientclientInstanceprivate SftpErrorDataHandlererrorDataHandlerprivate SftpClientFactoryfactoryprivate java.util.NavigableMap<java.lang.String,SftpFileSystem>fileSystemsprivate SftpFileSystemClientSessionInitializerfsSessionInitializerprotected org.slf4j.Loggerlogstatic java.util.Set<java.lang.Class<? extends java.nio.file.attribute.FileAttributeView>>UNIVERSAL_SUPPORTED_VIEWSstatic java.lang.StringVERSION_PARAMURI parameter that can be used to specify a special version selection.private SftpVersionSelectorversionSelector
-
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 intattributesToPermissions(java.nio.file.Path path, java.util.Collection<java.nio.file.attribute.PosixFilePermission> perms)voidcheckAccess(java.nio.file.Path path, java.nio.file.AccessMode... modes)voidcopy(java.nio.file.Path source, java.nio.file.Path target, java.nio.file.CopyOption... options)voidcreateDirectory(java.nio.file.Path dir, java.nio.file.attribute.FileAttribute<?>... attrs)static java.net.URIcreateFileSystemURI(java.lang.String host, int port, java.lang.String username, java.lang.String password)static java.net.URIcreateFileSystemURI(java.lang.String host, int port, java.lang.String username, java.lang.String password, java.util.Map<java.lang.String,?> params)voidcreateSymbolicLink(java.nio.file.Path link, java.nio.file.Path target, java.nio.file.attribute.FileAttribute<?>... attrs)voiddelete(java.nio.file.Path path)static java.lang.StringencodeCredentials(java.lang.String username, java.lang.String password)SshClientgetClientInstance()<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.FileStoregetFileStore(java.nio.file.Path path)SftpFileSystemgetFileSystem(java.lang.String id)java.nio.file.FileSystemgetFileSystem(java.net.URI uri)static java.lang.StringgetFileSystemIdentifier(java.lang.String host, int port, java.lang.String username)static java.lang.StringgetFileSystemIdentifier(java.net.URI uri)Uses the host, port and username to create a unique identifierstatic java.lang.StringgetFileSystemIdentifier(ClientSession session)Uses the remote host address, port and current username to create a unique identifierstatic java.lang.StringgetOctalPermissions(int perms)static java.lang.StringgetOctalPermissions(java.util.Collection<java.nio.file.attribute.PosixFilePermission> perms)java.nio.file.PathgetPath(java.net.URI uri)static java.lang.StringgetRWXPermissions(int perms)java.lang.StringgetScheme()SftpClientFactorygetSftpClientFactory()SftpErrorDataHandlergetSftpErrorDataHandler()SftpFileSystemClientSessionInitializergetSftpFileSystemClientSessionInitializer()SftpVersionSelectorgetSftpVersionSelector()booleanisHidden(java.nio.file.Path path)booleanisSameFile(java.nio.file.Path path1, java.nio.file.Path path2)booleanisSupportedFileAttributeView(java.nio.file.Path path, java.lang.Class<? extends java.nio.file.attribute.FileAttributeView> type)booleanisSupportedFileAttributeView(SftpFileSystem fs, java.lang.Class<? extends java.nio.file.attribute.FileAttributeView> type)voidmove(java.nio.file.Path source, java.nio.file.Path target, java.nio.file.CopyOption... options)java.nio.channels.FileChannelnewByteChannel(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.FileChannelnewFileChannel(java.nio.file.Path path, java.util.Set<? extends java.nio.file.OpenOption> options, java.nio.file.attribute.FileAttribute<?>... attrs)SftpFileSystemnewFileSystem(java.net.URI uri, java.util.Map<java.lang.String,?> env)SftpFileSystemnewFileSystem(ClientSession session)java.io.InputStreamnewInputStream(java.nio.file.Path path, java.nio.file.OpenOption... options)java.io.OutputStreamnewOutputStream(java.nio.file.Path path, java.nio.file.OpenOption... options)static MutableBasicCredentialsparseCredentials(java.lang.String userInfo)static MutableBasicCredentialsparseCredentials(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.AttributesreadRemoteAttributes(SftpPath path, java.nio.file.LinkOption... options)java.nio.file.PathreadSymbolicLink(java.nio.file.Path link)SftpFileSystemremoveFileSystem(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.AttributesresolveRemoteFileAttributes(SftpPath path, java.nio.file.LinkOption... options)protected SftpErrorDataHandlerresolveSftpErrorDataHandler(java.net.URI uri, SftpErrorDataHandler errorHandler, PropertyResolver resolver)protected SftpVersionSelectorresolveSftpVersionSelector(java.net.URI uri, SftpVersionSelector defaultSelector, PropertyResolver resolver)voidsetAttribute(java.nio.file.Path path, java.lang.String attribute, java.lang.Object value, java.nio.file.LinkOption... options)voidsetAttribute(java.nio.file.Path path, java.lang.String view, java.lang.String attr, java.lang.Object value, java.nio.file.LinkOption... options)voidsetSftpFileSystemClientSessionInitializer(SftpFileSystemClientSessionInitializer initializer)SftpPathtoSftpPath(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- 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:
SshClient.setUpDefaultClient()
-
-
Method Detail
-
getScheme
public java.lang.String getScheme()
- Specified by:
getSchemein 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:
newFileSystemin 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- TheURIvalue - ignored ifnullor does not contain anyuser info.- Returns:
- The parsed credentials -
nullif 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:
getFileSystemin 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-nullif no match
-
getFileSystem
public SftpFileSystem getFileSystem(java.lang.String id)
- Parameters:
id- File system identifier - ignored ifnull/empty- Returns:
- The cached
SftpFileSystem-nullif no match
-
getPath
public java.nio.file.Path getPath(java.net.URI uri)
- Specified by:
getPathin 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:
newByteChannelin 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:
newFileChannelin 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:
newInputStreamin 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:
newOutputStreamin 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:
newDirectoryStreamin 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:
createDirectoryin classjava.nio.file.spi.FileSystemProvider- Throws:
java.io.IOException
-
delete
public void delete(java.nio.file.Path path) throws java.io.IOException- Specified by:
deletein 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:
copyin 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:
movein 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:
isSameFilein classjava.nio.file.spi.FileSystemProvider- Throws:
java.io.IOException
-
isHidden
public boolean isHidden(java.nio.file.Path path) throws java.io.IOException- Specified by:
isHiddenin 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:
getFileStorein 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:
createSymbolicLinkin 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:
readSymbolicLinkin 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:
checkAccessin 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:
getFileAttributeViewin 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:
readAttributesin 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:
readAttributesin 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:
setAttributein 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)
-
-