Top Fields Methods
org.apache.sshd.sftp.server

public Interface SftpFileSystemAccessor

Imports
java.io.FileNotFoundException, .IOException, .StreamCorruptedException, java.nio.channels.Channel, .FileChannel, .FileLock, .SeekableByteChannel, java.nio.file.*, java.nio.file.attribute.AclEntry, .AclFileAttributeView, .FileAttribute, .FileOwnerAttributeView, .GroupPrincipal, .PosixFileAttributeView, .PosixFilePermission, .UserPrincipal, .UserPrincipalLookupService, .UserPrincipalNotFoundException, java.security.Principal, java.util.Arrays, .Collection, .Collections, .HashSet, .List, .Map, .NavigableMap, .Set, org.apache.sshd.common.PropertyResolverUtils, org.apache.sshd.common.util.GenericUtils, .MapEntryUtils.NavigableMapBuilder, .OsUtils, .SelectorUtils, org.apache.sshd.common.util.buffer.Buffer, org.apache.sshd.common.util.io.FileInfoExtractor, .IoUtils

Author
Apache MINA SSHD Project

Field Summary

Modifier and TypeField and Description
public static final SftpFileSystemAccessor
public static final boolean
DEFAULT_AUTO_SYNC_FILE_ON_CLOSE

Default value for sftp-auto-fsync-on-close if none set

public static final List<String>
public static final NavigableMap<String, FileInfoExtractor<?>>
FILEATTRS_RESOLVERS

A case insensitive NavigableMap of FileInfoExtractors to be used to complete attributes that are deemed important enough to warrant an extra effort if not accessible via the file system attributes views

public static final String
PROP_AUTO_SYNC_FILE_ON_CLOSE

Whether to invoke FileChannel#force(boolean) on files open for write when closing

Method Summary

Modifier and TypeMethod and Description
public default void
applyExtensionFileAttributes(SftpSubsystemProxy
The SFTP subsystem instance that manages the session
subsystem
,
Path
The referenced file
file
,
Map<String, byte[]>
The received extensions - may be null/empty
extensions
,
LinkOption...
The LinkOption-s that were used to access the file's standard attributes
options
)

Invoked in order to allow processing of custom file attributes

public default void
closeDirectory(SftpSubsystemProxy
The SFTP subsystem instance that manages the session
subsystem
,
DirectoryHandle
The DirectoryHandle representing the stream - may be null if not invoked within the context of such a handle (special cases)
dirHandle
,
Path
The requested local directory Path - same one returned by resolveLocalFilePath
dir
,
String
The assigned directory handle through which the remote peer references this directory
handle
,
DirectoryStream<Path>
The disposed DirectoryStream
ds
)

Called when a directory stream is no longer required

public default void
closeFile(SftpSubsystemProxy
The SFTP subsystem instance that manages the session
subsystem
,
FileHandle
The FileHandle representing the created channel - may be null if not invoked within the context of such a handle (special cases)
fileHandle
,
Path
The requested local file Path - same one returned by resolveLocalFilePath
file
,
String
The assigned file handle through which the remote peer references this file
handle
,
Channel channel, Set<? extends OpenOption>
The original options used to open the channel
options
)

Called to inform the accessor that it should close the file

public default void
public default void
public default boolean
public default DirectoryStream<Path>

Returns:

The opened DirectoryStream
openDirectory
(SftpSubsystemProxy
The SFTP subsystem instance that manages the session
subsystem
,
DirectoryHandle
The DirectoryHandle representing the stream
dirHandle
,
Path
The requested local directory Path - same one returned by resolveLocalFilePath
dir
,
String
The assigned directory handle through which the remote peer references this directory
handle
,
LinkOption...
The LinkOptions - OK if null/empty.
linkOptions
)

Called when a new directory stream is requested

public default SeekableByteChannel

Returns:

The opened SeekableByteChannel
openFile
(SftpSubsystemProxy
The SFTP subsystem instance that manages the session
subsystem
,
FileHandle
The FileHandle representing the created channel - may be null if not invoked within the context of such a handle (special cases)
fileHandle
,
Path
The requested local file Path - same one returned by resolveLocalFilePath
file
,
String
The assigned file handle through which the remote peer references this file. May be null/empty if the request is due to some internal functionality instead of due to peer requesting a handle to a file.
handle
,
Set<? extends OpenOption>
The requested OpenOptions
options
,
FileAttribute<?>...
The requested FileAttributes
attrs
)

Called whenever a new file is opened

public default void
putRemoteFileName(SftpSubsystemProxy
The SFTP subsystem instance that manages the session
subsystem
,
Path
The associated file Path - Note: might be a symbolic link container
path
,
Buffer
The target Buffer for the encoded string
buf
,
String
The string to send
name
,
boolean
If true then this is the "pure" file name/path, otherwise it also contains user/group/size/last-modified-time/etc.
shortName
)

Invoked in order to encode the outgoing referenced file name/path

public default Map<String, ?>

Returns:

A Map of all the attributes available for the file in the view
readFileAttributes
(SftpSubsystemProxy
The SFTP subsystem instance that manages the session
subsystem
,
Path
The requested local file Path - same one returned by resolveLocalFilePath
file
,
String
The required view name
view
,
LinkOption...
The access LinkOption-s
options
)

Invoked when required to retrieve file attributes for a specific file system view

public default void
removeFile(SftpSubsystemProxy subsystem, Path path, boolean isDirectory)

public default void
renameFile(SftpSubsystemProxy subsystem, Path oldPath, Path newPath, Collection<CopyOption> opts)

public default LinkOption[]

Returns:

The LinkOption-s to use - invokes IoUtils#getLinkOptions(boolean) by default
resolveFileAccessLinkOptions
(SftpSubsystemProxy
The SFTP subsystem instance that manages the session
subsystem
,
Path
The referenced file
file
,
int
The SFTP command that triggered this access
cmd
,
String
The SFTP extension that triggered this access - non-empty only for {SSH_FXP_EXTENDED} command
extension
,
boolean
Whether to follow symbolic links
followLinks
)

Invoked in order to determine the symbolic link follow options

public default UserPrincipal
public default GroupPrincipal
public default String
public default Path

Returns:

The local Path
resolveLocalFilePath
(SftpSubsystemProxy
The SFTP subsystem instance that manages the session
subsystem
,
Path
The default root directory used to resolve relative paths - a.k.a. the chroot location
rootDir
,
String
The remote path - separated by '/'
remotePath
)

Invoked in order to resolve remote file paths reference by the client into ones accessible by the server

public default NavigableMap<String, Object>

Returns:

The updated attributes map
resolveReportedFileAttributes
(SftpSubsystemProxy
The SFTP subsystem instance that manages the session
subsystem
,
Path
The referenced file
file
,
int
A mask of the original required attributes
flags
,
NavigableMap<String, Object>
The default resolved attributes map
attrs
,
LinkOption...
The LinkOption-s that were used to access the file's attributes
options
)

Invoked in order to allow intervention to the reported file attributes - e.g., add custom/extended properties

public static SecureDirectoryStream<Path>
public static SecureDirectoryStream<Path>
public static SeekableByteChannel
seekableByteChannelNoLinkFollow(Path src, Set<? extends OpenOption> opts, FileAttribute<?>... fileAttributes)

public default void
public default void
setFileAttribute(SftpSubsystemProxy
The SFTP subsystem instance that manages the session
subsystem
,
Path
The requested local file Path - same one returned by resolveLocalFilePath
file
,
String
The required view name
view
,
String
The attribute name
attribute
,
Object
The attribute value
value
,
LinkOption...
The access LinkOption-s
options
)

Sets a view attribute for a local file

public default void
setFileOwner(SftpSubsystemProxy subsystem, Path file, Principal value, LinkOption... options)

public default void
public default void
setGroupOwner(SftpSubsystemProxy subsystem, Path file, Principal value, LinkOption... options)

public default void
syncFileData(SftpSubsystemProxy
The SFTP subsystem instance that manages the session
subsystem
,
FileHandle
The FileHandle representing the created channel
fileHandle
,
Path
The requested local file Path - same one returned by resolveLocalFilePath
file
,
String
The assigned file handle through which the remote peer references this file
handle
,
Channel channel)

Called when file meta-data re-synchronization is required

public default FileLock

Returns:

A lock object representing the newly-acquired lock, or null if the lock could not be acquired because another program holds an overlapping lock
tryLock
(SftpSubsystemProxy
The SFTP subsystem instance that manages the session
subsystem
,
FileHandle
The FileHandle representing the created channel
fileHandle
,
Path
The requested local file Path - same one returned by resolveLocalFilePath
file
,
String
The assigned file handle through which the remote peer references this file
handle
,
Channel channel, long
The position at which the locked region is to start - must be non-negative
position
,
long
The size of the locked region; must be non-negative, and the sum position + size must be non-negative
size
,
boolean
true to request a shared lock, false to request an exclusive lock
shared
)

Called when locking a section of a file is requested

Field Detail

DEFAULTback to summary
public static final SftpFileSystemAccessor DEFAULT
DEFAULT_AUTO_SYNC_FILE_ON_CLOSEback to summary
public static final boolean DEFAULT_AUTO_SYNC_FILE_ON_CLOSE

Default value for sftp-auto-fsync-on-close if none set

DEFAULT_UNIX_VIEWback to summary
public static final List<String> DEFAULT_UNIX_VIEW
FILEATTRS_RESOLVERSback to summary
public static final NavigableMap<String, FileInfoExtractor<?>> FILEATTRS_RESOLVERS

A case insensitive NavigableMap of FileInfoExtractors to be used to complete attributes that are deemed important enough to warrant an extra effort if not accessible via the file system attributes views

PROP_AUTO_SYNC_FILE_ON_CLOSEback to summary
public static final String PROP_AUTO_SYNC_FILE_ON_CLOSE

Whether to invoke FileChannel#force(boolean) on files open for write when closing

Method Detail

applyExtensionFileAttributesback to summary
public default void applyExtensionFileAttributes(SftpSubsystemProxy subsystem, Path file, Map<String, byte[]> extensions, LinkOption... options) throws IOException

Invoked in order to allow processing of custom file attributes

Parameters
subsystem:SftpSubsystemProxy

The SFTP subsystem instance that manages the session

file:Path

The referenced file

extensions:Map<String, byte[]>

The received extensions - may be null/empty

options:LinkOption[]

The LinkOption-s that were used to access the file's standard attributes

Exceptions
IOException:
If failed to apply the attributes
closeDirectoryback to summary
public default void closeDirectory(SftpSubsystemProxy subsystem, DirectoryHandle dirHandle, Path dir, String handle, DirectoryStream<Path> ds) throws IOException

Called when a directory stream is no longer required

Parameters
subsystem:SftpSubsystemProxy

The SFTP subsystem instance that manages the session

dirHandle:DirectoryHandle

The DirectoryHandle representing the stream - may be null if not invoked within the context of such a handle (special cases)

dir:Path

The requested local directory Path - same one returned by resolveLocalFilePath

handle:String

The assigned directory handle through which the remote peer references this directory

ds:DirectoryStream<Path>

The disposed DirectoryStream

Exceptions
IOException:
If failed to open
closeFileback to summary
public default void closeFile(SftpSubsystemProxy subsystem, FileHandle fileHandle, Path file, String handle, Channel channel, Set<? extends OpenOption> options) throws IOException

Called to inform the accessor that it should close the file

Parameters
subsystem:SftpSubsystemProxy

The SFTP subsystem instance that manages the session

fileHandle:FileHandle

The FileHandle representing the created channel - may be null if not invoked within the context of such a handle (special cases)

file:Path

The requested local file Path - same one returned by resolveLocalFilePath

handle:String

The assigned file handle through which the remote peer references this file

channel:Channel

The original Channel that was returned by openFile(SftpSubsystemProxy, FileHandle, Path, String, Set, FileAttribute...)

options:Set<? extends OpenOption>

The original options used to open the channel

Exceptions
IOException:
If failed to execute the request
copyFileback to summary
public default void copyFile(SftpSubsystemProxy subsystem, Path src, Path dst, Collection<CopyOption> opts) throws IOException
createDirectoryback to summary
public default void createDirectory(SftpSubsystemProxy subsystem, Path path) throws IOException
noFollowback to summary
public default boolean noFollow(Collection<?> opts)
openDirectoryback to summary
public default DirectoryStream<Path> openDirectory(SftpSubsystemProxy subsystem, DirectoryHandle dirHandle, Path dir, String handle, LinkOption... linkOptions) throws IOException

Called when a new directory stream is requested

Parameters
subsystem:SftpSubsystemProxy

The SFTP subsystem instance that manages the session

dirHandle:DirectoryHandle

The DirectoryHandle representing the stream

dir:Path

The requested local directory Path - same one returned by resolveLocalFilePath

handle:String

The assigned directory handle through which the remote peer references this directory

linkOptions:LinkOption[]

The LinkOptions - OK if null/empty.

Returns:DirectoryStream<Path>

The opened DirectoryStream

Exceptions
IOException:
If failed to open
openFileback to summary
public default SeekableByteChannel openFile(SftpSubsystemProxy subsystem, FileHandle fileHandle, Path file, String handle, Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException

Called whenever a new file is opened

Parameters
subsystem:SftpSubsystemProxy

The SFTP subsystem instance that manages the session

fileHandle:FileHandle

The FileHandle representing the created channel - may be null if not invoked within the context of such a handle (special cases)

file:Path

The requested local file Path - same one returned by resolveLocalFilePath

handle:String

The assigned file handle through which the remote peer references this file. May be null/empty if the request is due to some internal functionality instead of due to peer requesting a handle to a file.

options:Set<? extends OpenOption>

The requested OpenOptions

attrs:FileAttribute<?>[]

The requested FileAttributes

Returns:SeekableByteChannel

The opened SeekableByteChannel

Exceptions
IOException:
If failed to open
putRemoteFileNameback to summary
public default void putRemoteFileName(SftpSubsystemProxy subsystem, Path path, Buffer buf, String name, boolean shortName) throws IOException

Invoked in order to encode the outgoing referenced file name/path

Parameters
subsystem:SftpSubsystemProxy

The SFTP subsystem instance that manages the session

path:Path

The associated file Path - Note: might be a symbolic link container

buf:Buffer

The target Buffer for the encoded string

name:String

The string to send

shortName:boolean

If true then this is the "pure" file name/path, otherwise it also contains user/group/size/last-modified-time/etc.

Exceptions
IOException:
If failed to resolve the remote name
See Also
SSHD-1132
readFileAttributesback to summary
public default Map<String, ?> readFileAttributes(SftpSubsystemProxy subsystem, Path file, String view, LinkOption... options) throws IOException

Invoked when required to retrieve file attributes for a specific file system view

Parameters
subsystem:SftpSubsystemProxy

The SFTP subsystem instance that manages the session

file:Path

The requested local file Path - same one returned by resolveLocalFilePath

view:String

The required view name

options:LinkOption[]

The access LinkOption-s

Returns:Map<String, ?>

A Map of all the attributes available for the file in the view

Exceptions
IOException:
If failed to read the attributes
See Also
Files#readAttributes(Path, String, LinkOption...)
removeFileback to summary
public default void removeFile(SftpSubsystemProxy subsystem, Path path, boolean isDirectory) throws IOException
renameFileback to summary
public default void renameFile(SftpSubsystemProxy subsystem, Path oldPath, Path newPath, Collection<CopyOption> opts) throws IOException
resolveFileAccessLinkOptionsback to summary
public default LinkOption[] resolveFileAccessLinkOptions(SftpSubsystemProxy subsystem, Path file, int cmd, String extension, boolean followLinks) throws IOException

Invoked in order to determine the symbolic link follow options

Parameters
subsystem:SftpSubsystemProxy

The SFTP subsystem instance that manages the session

file:Path

The referenced file

cmd:int

The SFTP command that triggered this access

extension:String

The SFTP extension that triggered this access - non-empty only for {SSH_FXP_EXTENDED} command

followLinks:boolean

Whether to follow symbolic links

Returns:LinkOption[]

The LinkOption-s to use - invokes IoUtils#getLinkOptions(boolean) by default

Exceptions
IOException:
if failed to resolve the required options
See Also
SSHD-1137
resolveFileOwnerback to summary
public default UserPrincipal resolveFileOwner(SftpSubsystemProxy subsystem, Path file, UserPrincipal name) throws IOException
resolveGroupOwnerback to summary
public default GroupPrincipal resolveGroupOwner(SftpSubsystemProxy subsystem, Path file, GroupPrincipal name) throws IOException
resolveLinkTargetback to summary
public default String resolveLinkTarget(SftpSubsystemProxy subsystem, Path link) throws IOException
resolveLocalFilePathback to summary
public default Path resolveLocalFilePath(SftpSubsystemProxy subsystem, Path rootDir, String remotePath) throws IOException, InvalidPathException

Invoked in order to resolve remote file paths reference by the client into ones accessible by the server

Parameters
subsystem:SftpSubsystemProxy

The SFTP subsystem instance that manages the session

rootDir:Path

The default root directory used to resolve relative paths - a.k.a. the chroot location

remotePath:String

The remote path - separated by '/'

Returns:Path

The local Path

Exceptions
IOException:
If failed to resolve the local path
InvalidPathException:
If bad local path specification
See Also
SftpSubsystemEnvironment#getDefaultDirectory()
resolveReportedFileAttributesback to summary
public default NavigableMap<String, Object> resolveReportedFileAttributes(SftpSubsystemProxy subsystem, Path file, int flags, NavigableMap<String, Object> attrs, LinkOption... options) throws IOException

Invoked in order to allow intervention to the reported file attributes - e.g., add custom/extended properties

Parameters
subsystem:SftpSubsystemProxy

The SFTP subsystem instance that manages the session

file:Path

The referenced file

flags:int

A mask of the original required attributes

attrs:NavigableMap<String, Object>

The default resolved attributes map

options:LinkOption[]

The LinkOption-s that were used to access the file's attributes

Returns:NavigableMap<String, Object>

The updated attributes map

Exceptions
IOException:
If failed to resolve the attributes
See Also
SSHD-1226
secureback to summary
public static SecureDirectoryStream<Path> secure(DirectoryStream<Path> ds)
secureResolveDirectoryStreamback to summary
public static SecureDirectoryStream<Path> secureResolveDirectoryStream(Path toResolve) throws IOException
seekableByteChannelNoLinkFollowback to summary
public static SeekableByteChannel seekableByteChannelNoLinkFollow(Path src, Set<? extends OpenOption> opts, FileAttribute<?>... fileAttributes) throws IOException
setFileAccessControlback to summary
public default void setFileAccessControl(SftpSubsystemProxy subsystem, Path file, List<AclEntry> acl, LinkOption... options) throws IOException
setFileAttributeback to summary
public default void setFileAttribute(SftpSubsystemProxy subsystem, Path file, String view, String attribute, Object value, LinkOption... options) throws IOException

Sets a view attribute for a local file

Parameters
subsystem:SftpSubsystemProxy

The SFTP subsystem instance that manages the session

file:Path

The requested local file Path - same one returned by resolveLocalFilePath

view:String

The required view name

attribute:String

The attribute name

value:Object

The attribute value

options:LinkOption[]

The access LinkOption-s

Exceptions
IOException:
If failed to set the attribute
setFileOwnerback to summary
public default void setFileOwner(SftpSubsystemProxy subsystem, Path file, Principal value, LinkOption... options) throws IOException
setFilePermissionsback to summary
public default void setFilePermissions(SftpSubsystemProxy subsystem, Path file, Set<PosixFilePermission> perms, LinkOption... options) throws IOException
setGroupOwnerback to summary
public default void setGroupOwner(SftpSubsystemProxy subsystem, Path file, Principal value, LinkOption... options) throws IOException
syncFileDataback to summary
public default void syncFileData(SftpSubsystemProxy subsystem, FileHandle fileHandle, Path file, String handle, Channel channel) throws IOException

Called when file meta-data re-synchronization is required

Parameters
subsystem:SftpSubsystemProxy

The SFTP subsystem instance that manages the session

fileHandle:FileHandle

The FileHandle representing the created channel

file:Path

The requested local file Path - same one returned by resolveLocalFilePath

handle:String

The assigned file handle through which the remote peer references this file

channel:Channel

The original Channel that was returned by openFile(SftpSubsystemProxy, FileHandle, Path, String, Set, FileAttribute...)

Exceptions
IOException:
If failed to execute the request
See Also
FileChannel#force(boolean), OpenSSH - section 10
tryLockback to summary
public default FileLock tryLock(SftpSubsystemProxy subsystem, FileHandle fileHandle, Path file, String handle, Channel channel, long position, long size, boolean shared) throws IOException

Called when locking a section of a file is requested

Parameters
subsystem:SftpSubsystemProxy

The SFTP subsystem instance that manages the session

fileHandle:FileHandle

The FileHandle representing the created channel

file:Path

The requested local file Path - same one returned by resolveLocalFilePath

handle:String

The assigned file handle through which the remote peer references this file

channel:Channel

The original Channel that was returned by openFile(SftpSubsystemProxy, FileHandle, Path, String, Set, FileAttribute...)

position:long

The position at which the locked region is to start - must be non-negative

size:long

The size of the locked region; must be non-negative, and the sum position + size must be non-negative

shared:boolean

true to request a shared lock, false to request an exclusive lock

Returns:FileLock

A lock object representing the newly-acquired lock, or null if the lock could not be acquired because another program holds an overlapping lock

Annotations
@SuppressWarnings:checkstyle:ParameterNumber
Exceptions
IOException:
If failed to honor the request
See Also
FileChannel#tryLock(long, long, boolean)