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 FileSystemProvider
A 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"- Author:
- Apache MINA SSHD Project
-
-
Field Summary
Fields Modifier and Type Field Description protected org.slf4j.Loggerlogstatic Set<Class<? extends FileAttributeView>>UNIVERSAL_SUPPORTED_VIEWSstatic StringVERSION_PARAMURI parameter that can be used to specify a special version selection.
-
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
-
Methods inherited from class java.nio.file.spi.FileSystemProvider
createLink, deleteIfExists, installedProviders, newAsynchronousFileChannel, newFileSystem
-
-
-
-
Field Detail
-
VERSION_PARAM
public static final 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 Set<Class<? extends FileAttributeView>> UNIVERSAL_SUPPORTED_VIEWS
-
log
protected final org.slf4j.Logger log
-
-
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 String getScheme()
- Specified by:
getSchemein classFileSystemProvider
-
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(URI uri, Map<String,?> env) throws IOException
- 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
public static Map<String,Object> resolveFileSystemParameters(Map<String,?> env, Map<String,Object> uriParams)
-
parseCredentials
public static MutableBasicCredentials parseCredentials(URI uri)
Attempts to parse the user information from the URI
-
parseCredentials
public static MutableBasicCredentials parseCredentials(String userInfo)
-
newFileSystem
public SftpFileSystem newFileSystem(ClientSession session) throws IOException
- Throws:
IOException
-
getFileSystem
public FileSystem getFileSystem(URI uri)
- Specified by:
getFileSystemin classFileSystemProvider
-
removeFileSystem
public SftpFileSystem removeFileSystem(String id)
- Parameters:
id- File system identifier - ignored ifnull/empty- Returns:
- The removed
SftpFileSystem-nullif no match
-
getFileSystem
public SftpFileSystem getFileSystem(String id)
- Parameters:
id- File system identifier - ignored ifnull/empty- Returns:
- The cached
SftpFileSystem-nullif no match
-
getPath
public Path getPath(URI uri)
- 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
public InputStream newInputStream(Path path, OpenOption... options) throws IOException
- Overrides:
newInputStreamin classFileSystemProvider- Throws:
IOException
-
newOutputStream
public OutputStream newOutputStream(Path path, OpenOption... options) throws IOException
- 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
public void createDirectory(Path dir, FileAttribute<?>... attrs) throws IOException
- Specified by:
createDirectoryin classFileSystemProvider- Throws:
IOException
-
delete
public void delete(Path path) throws IOException
- Specified by:
deletein classFileSystemProvider- Throws:
IOException
-
copy
public void copy(Path source, Path target, CopyOption... options) throws IOException
- Specified by:
copyin classFileSystemProvider- Throws:
IOException
-
move
public void move(Path source, Path target, CopyOption... options) throws IOException
- Specified by:
movein classFileSystemProvider- Throws:
IOException
-
isSameFile
public boolean isSameFile(Path path1, Path path2) throws IOException
- Specified by:
isSameFilein classFileSystemProvider- Throws:
IOException
-
isHidden
public boolean isHidden(Path path) throws IOException
- Specified by:
isHiddenin classFileSystemProvider- Throws:
IOException
-
getFileStore
public FileStore getFileStore(Path path) throws IOException
- Specified by:
getFileStorein classFileSystemProvider- Throws:
IOException
-
createSymbolicLink
public void createSymbolicLink(Path link, Path target, FileAttribute<?>... attrs) throws IOException
- Overrides:
createSymbolicLinkin classFileSystemProvider- Throws:
IOException
-
readSymbolicLink
public Path readSymbolicLink(Path link) throws IOException
- Overrides:
readSymbolicLinkin classFileSystemProvider- Throws:
IOException
-
checkAccess
public void checkAccess(Path path, AccessMode... modes) throws IOException
- 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
public boolean isSupportedFileAttributeView(Path path, Class<? extends FileAttributeView> type)
-
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
-
attributesToPermissions
protected int attributesToPermissions(Path path, Collection<PosixFilePermission> perms)
-
getRWXPermissions
public static String getRWXPermissions(int perms)
-
getOctalPermissions
public static String getOctalPermissions(int perms)
-
permissionsToAttributes
public static Set<PosixFilePermission> permissionsToAttributes(int perms)
-
getOctalPermissions
public static String getOctalPermissions(Collection<PosixFilePermission> perms)
-
getFileSystemIdentifier
public static String getFileSystemIdentifier(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 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 String getFileSystemIdentifier(String host, int port, String username)
-
createFileSystemURI
public static URI createFileSystemURI(String host, int port, String username, String password)
-
createFileSystemURI
public static URI createFileSystemURI(String host, int port, String username, String password, Map<String,?> params)
-
-