Class SftpFileSystemProvider
- java.lang.Object
-
- java.nio.file.spi.FileSystemProvider
-
- org.apache.sshd.client.subsystem.sftp.fs.SftpFileSystemProvider
-
public class SftpFileSystemProvider extends FileSystemProvider
A registeredFileSystemProvider
that 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 static String
AUTH_TIME_PROP_NAME
static String
CONNECT_TIME_PROP_NAME
static long
DEFAULT_AUTH_TIME
static long
DEFAULT_CONNECT_TIME
static Charset
DEFAULT_NAME_DECODER_CHARSET
static int
DEFAULT_READ_BUFFER_SIZE
static int
DEFAULT_WRITE_BUFFER_SIZE
protected org.slf4j.Logger
log
static String
NAME_DECORDER_CHARSET_PROP_NAME
static String
READ_BUFFER_PROP_NAME
static Set<Class<? extends FileAttributeView>>
UNIVERSAL_SUPPORTED_VIEWS
static String
VERSION_PARAM
URI parameter that can be used to specify a special version selection.static String
WRITE_BUFFER_PROP_NAME
-
Constructor Summary
Constructors Constructor Description SftpFileSystemProvider()
SftpFileSystemProvider(SshClient client)
SftpFileSystemProvider(SshClient client, SftpClientFactory factory, SftpVersionSelector selector)
SftpFileSystemProvider(SshClient client, SftpVersionSelector selector)
SftpFileSystemProvider(SftpVersionSelector selector)
-
Method Summary
-
Methods inherited from class java.nio.file.spi.FileSystemProvider
createLink, deleteIfExists, installedProviders, newAsynchronousFileChannel, newFileSystem, newInputStream, newOutputStream
-
-
-
-
Field Detail
-
READ_BUFFER_PROP_NAME
public static final String READ_BUFFER_PROP_NAME
- See Also:
- Constant Field Values
-
DEFAULT_READ_BUFFER_SIZE
public static final int DEFAULT_READ_BUFFER_SIZE
- See Also:
- Constant Field Values
-
WRITE_BUFFER_PROP_NAME
public static final String WRITE_BUFFER_PROP_NAME
- See Also:
- Constant Field Values
-
DEFAULT_WRITE_BUFFER_SIZE
public static final int DEFAULT_WRITE_BUFFER_SIZE
- See Also:
- Constant Field Values
-
CONNECT_TIME_PROP_NAME
public static final String CONNECT_TIME_PROP_NAME
- See Also:
- Constant Field Values
-
DEFAULT_CONNECT_TIME
public static final long DEFAULT_CONNECT_TIME
-
AUTH_TIME_PROP_NAME
public static final String AUTH_TIME_PROP_NAME
- See Also:
- Constant Field Values
-
DEFAULT_AUTH_TIME
public static final long DEFAULT_AUTH_TIME
-
NAME_DECORDER_CHARSET_PROP_NAME
public static final String NAME_DECORDER_CHARSET_PROP_NAME
- See Also:
- Constant Field Values
-
DEFAULT_NAME_DECODER_CHARSET
public static final Charset DEFAULT_NAME_DECODER_CHARSET
-
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)
- 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:
SshClient.setUpDefaultClient()
-
SftpFileSystemProvider
public SftpFileSystemProvider(SshClient client, SftpVersionSelector selector)
-
SftpFileSystemProvider
public SftpFileSystemProvider(SshClient client, SftpClientFactory factory, SftpVersionSelector selector)
-
-
Method Detail
-
getScheme
public String getScheme()
- Specified by:
getScheme
in classFileSystemProvider
-
getSftpVersionSelector
public final SftpVersionSelector getSftpVersionSelector()
-
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:
newFileSystem
in classFileSystemProvider
- Throws:
IOException
-
resolveSftpVersionSelector
protected SftpVersionSelector resolveSftpVersionSelector(URI uri, SftpVersionSelector defaultSelector, 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:
getFileSystem
in classFileSystemProvider
-
removeFileSystem
public SftpFileSystem removeFileSystem(String id)
- Parameters:
id
- File system identifier - ignored ifnull
/empty- Returns:
- The removed
SftpFileSystem
-null
if no match
-
getFileSystem
public SftpFileSystem getFileSystem(String id)
- Parameters:
id
- File system identifier - ignored ifnull
/empty- Returns:
- The cached
SftpFileSystem
-null
if no match
-
getPath
public Path getPath(URI uri)
- 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
-
newDirectoryStream
public DirectoryStream<Path> newDirectoryStream(Path dir, DirectoryStream.Filter<? super Path> filter) throws IOException
- Specified by:
newDirectoryStream
in classFileSystemProvider
- Throws:
IOException
-
createDirectory
public void createDirectory(Path dir, FileAttribute<?>... attrs) throws IOException
- Specified by:
createDirectory
in classFileSystemProvider
- Throws:
IOException
-
delete
public void delete(Path path) throws IOException
- Specified by:
delete
in classFileSystemProvider
- Throws:
IOException
-
copy
public void copy(Path source, Path target, CopyOption... options) throws IOException
- Specified by:
copy
in classFileSystemProvider
- Throws:
IOException
-
move
public void move(Path source, Path target, CopyOption... options) throws IOException
- Specified by:
move
in classFileSystemProvider
- Throws:
IOException
-
isSameFile
public boolean isSameFile(Path path1, Path path2) throws IOException
- Specified by:
isSameFile
in classFileSystemProvider
- Throws:
IOException
-
isHidden
public boolean isHidden(Path path) throws IOException
- Specified by:
isHidden
in classFileSystemProvider
- Throws:
IOException
-
getFileStore
public FileStore getFileStore(Path path) throws IOException
- 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
public Path readSymbolicLink(Path link) throws IOException
- Overrides:
readSymbolicLink
in classFileSystemProvider
- Throws:
IOException
-
checkAccess
public void checkAccess(Path path, AccessMode... modes) throws IOException
- 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
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:
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
-
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)
-
-