Package org.apache.sshd.sftp.server
Interface SftpFileSystemAccessor
public interface SftpFileSystemAccessor
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final SftpFileSystemAccessor
static final boolean
Default value for "sftp-auto-fsync-on-close" if none setstatic final NavigableMap<String,
FileInfoExtractor<?>> A case insensitiveNavigableMap
ofFileInfoExtractor
s to be used to complete attributes that are deemed important enough to warrant an extra effort if not accessible via the file system attributes viewsstatic final String
Whether to invokeFileChannel.force(boolean)
on files open for write when closing -
Method Summary
Modifier and TypeMethodDescriptiondefault void
closeDirectory
(ServerSession session, SftpSubsystemProxy subsystem, DirectoryHandle dirHandle, Path dir, String handle, DirectoryStream<Path> ds) Called when a directory stream is no longer requireddefault void
closeFile
(ServerSession session, SftpSubsystemProxy subsystem, FileHandle fileHandle, Path file, String handle, Channel channel, Set<? extends OpenOption> options) Called to inform the accessor that it should close the filedefault void
copyFile
(ServerSession session, SftpSubsystemProxy subsystem, Path src, Path dst, Collection<CopyOption> opts) default void
createDirectory
(ServerSession session, SftpSubsystemProxy subsystem, Path path) default void
createLink
(ServerSession session, SftpSubsystemProxy subsystem, Path link, Path existing, boolean symLink) Invoked in order to create a link to a pathdefault DirectoryStream<Path>
openDirectory
(ServerSession session, SftpSubsystemProxy subsystem, DirectoryHandle dirHandle, Path dir, String handle) Called when a new directory stream is requesteddefault SeekableByteChannel
openFile
(ServerSession session, SftpSubsystemProxy subsystem, FileHandle fileHandle, Path file, String handle, Set<? extends OpenOption> options, FileAttribute<?>... attrs) Called whenever a new file is openedreadFileAttributes
(ServerSession session, SftpSubsystemProxy subsystem, Path file, String view, LinkOption... options) Invoked when required to retrieve file attributes for a specific file system viewdefault void
removeFile
(ServerSession session, SftpSubsystemProxy subsystem, Path path, boolean isDirectory) default void
renameFile
(ServerSession session, SftpSubsystemProxy subsystem, Path oldPath, Path newPath, Collection<CopyOption> opts) default UserPrincipal
resolveFileOwner
(ServerSession session, SftpSubsystemProxy subsystem, Path file, UserPrincipal name) default GroupPrincipal
resolveGroupOwner
(ServerSession session, SftpSubsystemProxy subsystem, Path file, GroupPrincipal name) default String
resolveLinkTarget
(ServerSession session, SftpSubsystemProxy subsystem, Path link) default Path
resolveLocalFilePath
(ServerSession session, SftpSubsystemProxy subsystem, Path rootDir, String remotePath) Invoked in order to resolve remote file paths reference by the client into ones accessible by the serverdefault void
setFileAccessControl
(ServerSession session, SftpSubsystemProxy subsystem, Path file, List<AclEntry> acl, LinkOption... options) default void
setFileAttribute
(ServerSession session, SftpSubsystemProxy subsystem, Path file, String view, String attribute, Object value, LinkOption... options) Sets a view attribute for a local filedefault void
setFileOwner
(ServerSession session, SftpSubsystemProxy subsystem, Path file, Principal value, LinkOption... options) default void
setFilePermissions
(ServerSession session, SftpSubsystemProxy subsystem, Path file, Set<PosixFilePermission> perms, LinkOption... options) default void
setGroupOwner
(ServerSession session, SftpSubsystemProxy subsystem, Path file, Principal value, LinkOption... options) default void
syncFileData
(ServerSession session, SftpSubsystemProxy subsystem, FileHandle fileHandle, Path file, String handle, Channel channel) Called when file meta-data re-synchronization is requireddefault FileLock
tryLock
(ServerSession session, SftpSubsystemProxy subsystem, FileHandle fileHandle, Path file, String handle, Channel channel, long position, long size, boolean shared) Called when locking a section of a file is requested
-
Field Details
-
DEFAULT_UNIX_VIEW
-
FILEATTRS_RESOLVERS
A case insensitiveNavigableMap
ofFileInfoExtractor
s 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_CLOSE
Whether to invokeFileChannel.force(boolean)
on files open for write when closing- See Also:
-
DEFAULT_AUTO_SYNC_FILE_ON_CLOSE
static final boolean DEFAULT_AUTO_SYNC_FILE_ON_CLOSEDefault value for "sftp-auto-fsync-on-close" if none set- See Also:
-
DEFAULT
-
-
Method Details
-
resolveLocalFilePath
default Path resolveLocalFilePath(ServerSession session, 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:
session
- TheServerSession
through which the request was receivedsubsystem
- The SFTP subsystem instance that manages the sessionrootDir
- The default root directory used to resolve relative paths - a.k.a. thechroot
locationremotePath
- The remote path - separated by '/'- Returns:
- The local
Path
- Throws:
IOException
- If failed to resolve the local pathInvalidPathException
- If bad local path specification- See Also:
-
openFile
default SeekableByteChannel openFile(ServerSession session, SftpSubsystemProxy subsystem, FileHandle fileHandle, Path file, String handle, Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException Called whenever a new file is opened- Parameters:
session
- TheServerSession
through which the request was receivedsubsystem
- The SFTP subsystem instance that manages the sessionfileHandle
- TheFileHandle
representing the created channel - may benull
if not invoked within the context of such a handle (special cases)file
- The requested local filePath
- same one returned byresolveLocalFilePath
handle
- The assigned file handle through which the remote peer references this file. May benull
/empty if the request is due to some internal functionality instead of due to peer requesting a handle to a file.options
- The requestedOpenOption
sattrs
- The requestedFileAttribute
s- Returns:
- The opened
SeekableByteChannel
- Throws:
IOException
- If failed to open
-
tryLock
default FileLock tryLock(ServerSession session, 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:
session
- TheServerSession
through which the request was receivedsubsystem
- The SFTP subsystem instance that manages the sessionfileHandle
- TheFileHandle
representing the created channelfile
- The requested local filePath
- same one returned byresolveLocalFilePath
handle
- The assigned file handle through which the remote peer references this filechannel
- The originalChannel
that was returned byopenFile(ServerSession, SftpSubsystemProxy, FileHandle, Path, String, Set, FileAttribute...)
position
- The position at which the locked region is to start - must be non-negativesize
- The size of the locked region; must be non-negative, and the sum position + size must be non-negativeshared
-true
to request a shared lock,false
to request an exclusive lock- 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 - Throws:
IOException
- If failed to honor the request- See Also:
-
syncFileData
default void syncFileData(ServerSession session, SftpSubsystemProxy subsystem, FileHandle fileHandle, Path file, String handle, Channel channel) throws IOException Called when file meta-data re-synchronization is required- Parameters:
session
- TheServerSession
through which the request was receivedsubsystem
- The SFTP subsystem instance that manages the sessionfileHandle
- TheFileHandle
representing the created channelfile
- The requested local filePath
- same one returned byresolveLocalFilePath
handle
- The assigned file handle through which the remote peer references this filechannel
- The originalChannel
that was returned byopenFile(ServerSession, SftpSubsystemProxy, FileHandle, Path, String, Set, FileAttribute...)
- Throws:
IOException
- If failed to execute the request- See Also:
-
closeFile
default void closeFile(ServerSession session, 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:
session
- TheServerSession
through which the request was receivedsubsystem
- The SFTP subsystem instance that manages the sessionfileHandle
- TheFileHandle
representing the created channel - may benull
if not invoked within the context of such a handle (special cases)file
- The requested local filePath
- same one returned byresolveLocalFilePath
handle
- The assigned file handle through which the remote peer references this filechannel
- The originalChannel
that was returned byopenFile(ServerSession, SftpSubsystemProxy, FileHandle, Path, String, Set, FileAttribute...)
options
- The original options used to open the channel- Throws:
IOException
- If failed to execute the request
-
openDirectory
default DirectoryStream<Path> openDirectory(ServerSession session, SftpSubsystemProxy subsystem, DirectoryHandle dirHandle, Path dir, String handle) throws IOException Called when a new directory stream is requested- Parameters:
session
- TheServerSession
through which the request was receivedsubsystem
- The SFTP subsystem instance that manages the sessiondirHandle
- TheDirectoryHandle
representing the streamdir
- The requested local directoryPath
- same one returned byresolveLocalFilePath
handle
- The assigned directory handle through which the remote peer references this directory- Returns:
- The opened
DirectoryStream
- Throws:
IOException
- If failed to open
-
closeDirectory
default void closeDirectory(ServerSession session, SftpSubsystemProxy subsystem, DirectoryHandle dirHandle, Path dir, String handle, DirectoryStream<Path> ds) throws IOException Called when a directory stream is no longer required- Parameters:
session
- TheServerSession
through which the request was receivedsubsystem
- The SFTP subsystem instance that manages the sessiondirHandle
- TheDirectoryHandle
representing the stream - may benull
if not invoked within the context of such a handle (special cases)dir
- The requested local directoryPath
- same one returned byresolveLocalFilePath
handle
- The assigned directory handle through which the remote peer references this directoryds
- The disposedDirectoryStream
- Throws:
IOException
- If failed to open
-
readFileAttributes
default Map<String,?> readFileAttributes(ServerSession session, SftpSubsystemProxy subsystem, Path file, String view, LinkOption... options) throws IOException Invoked when required to retrieve file attributes for a specific file system view- Parameters:
session
- TheServerSession
through which the request was receivedsubsystem
- The SFTP subsystem instance that manages the sessionfile
- The requested local filePath
- same one returned byresolveLocalFilePath
view
- The required view nameoptions
- The accessLinkOption
-s- Returns:
- A
Map
of all the attributes available for the file in the view - Throws:
IOException
- If failed to read the attributes- See Also:
-
setFileAttribute
default void setFileAttribute(ServerSession session, SftpSubsystemProxy subsystem, Path file, String view, String attribute, Object value, LinkOption... options) throws IOException Sets a view attribute for a local file- Parameters:
session
- TheServerSession
through which the request was receivedsubsystem
- The SFTP subsystem instance that manages the sessionfile
- The requested local filePath
- same one returned byresolveLocalFilePath
view
- The required view nameattribute
- The attribute namevalue
- The attribute valueoptions
- The accessLinkOption
-s- Throws:
IOException
- If failed to set the attribute
-
resolveFileOwner
default UserPrincipal resolveFileOwner(ServerSession session, SftpSubsystemProxy subsystem, Path file, UserPrincipal name) throws IOException - Throws:
IOException
-
setFileOwner
default void setFileOwner(ServerSession session, SftpSubsystemProxy subsystem, Path file, Principal value, LinkOption... options) throws IOException - Throws:
IOException
-
resolveGroupOwner
default GroupPrincipal resolveGroupOwner(ServerSession session, SftpSubsystemProxy subsystem, Path file, GroupPrincipal name) throws IOException - Throws:
IOException
-
setGroupOwner
default void setGroupOwner(ServerSession session, SftpSubsystemProxy subsystem, Path file, Principal value, LinkOption... options) throws IOException - Throws:
IOException
-
setFilePermissions
default void setFilePermissions(ServerSession session, SftpSubsystemProxy subsystem, Path file, Set<PosixFilePermission> perms, LinkOption... options) throws IOException - Throws:
IOException
-
setFileAccessControl
default void setFileAccessControl(ServerSession session, SftpSubsystemProxy subsystem, Path file, List<AclEntry> acl, LinkOption... options) throws IOException - Throws:
IOException
-
createDirectory
default void createDirectory(ServerSession session, SftpSubsystemProxy subsystem, Path path) throws IOException - Throws:
IOException
-
createLink
default void createLink(ServerSession session, SftpSubsystemProxy subsystem, Path link, Path existing, boolean symLink) throws IOException Invoked in order to create a link to a path- Parameters:
session
- TheServerSession
through which the request was receivedsubsystem
- The SFTP subsystem instance that manages the sessionlink
- The requested linkPath
- same one returned byresolveLocalFilePath
existing
- The existingPath
that the link should referencesymLink
-true
if this should be a symbolic link- Throws:
IOException
- If failed to create the link- See Also:
-
resolveLinkTarget
default String resolveLinkTarget(ServerSession session, SftpSubsystemProxy subsystem, Path link) throws IOException - Throws:
IOException
-
renameFile
default void renameFile(ServerSession session, SftpSubsystemProxy subsystem, Path oldPath, Path newPath, Collection<CopyOption> opts) throws IOException - Throws:
IOException
-
copyFile
default void copyFile(ServerSession session, SftpSubsystemProxy subsystem, Path src, Path dst, Collection<CopyOption> opts) throws IOException - Throws:
IOException
-
removeFile
default void removeFile(ServerSession session, SftpSubsystemProxy subsystem, Path path, boolean isDirectory) throws IOException - Throws:
IOException
-