Package org.apache.sshd.sftp.server
Interface SftpFileSystemAccessor
-
public interface SftpFileSystemAccessor
-
-
Field Summary
Fields Modifier and Type Field Description static SftpFileSystemAccessorDEFAULTstatic booleanDEFAULT_AUTO_SYNC_FILE_ON_CLOSEDefault value for "sftp-auto-fsync-on-close" if none setstatic java.util.List<java.lang.String>DEFAULT_UNIX_VIEWstatic java.util.NavigableMap<java.lang.String,FileInfoExtractor<?>>FILEATTRS_RESOLVERSA case insensitiveNavigableMapofFileInfoExtractors 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 java.lang.StringPROP_AUTO_SYNC_FILE_ON_CLOSEWhether to invokeFileChannel.force(boolean)on files open for write when closing
-
Method Summary
All Methods Instance Methods Default Methods Modifier and Type Method Description default voidcloseDirectory(ServerSession session, SftpSubsystemProxy subsystem, DirectoryHandle dirHandle, java.nio.file.Path dir, java.lang.String handle, java.nio.file.DirectoryStream<java.nio.file.Path> ds)Called when a directory stream is no longer requireddefault voidcloseFile(ServerSession session, SftpSubsystemProxy subsystem, FileHandle fileHandle, java.nio.file.Path file, java.lang.String handle, java.nio.channels.Channel channel, java.util.Set<? extends java.nio.file.OpenOption> options)Called to inform the accessor that it should close the filedefault voidcopyFile(ServerSession session, SftpSubsystemProxy subsystem, java.nio.file.Path src, java.nio.file.Path dst, java.util.Collection<java.nio.file.CopyOption> opts)default voidcreateDirectory(ServerSession session, SftpSubsystemProxy subsystem, java.nio.file.Path path)default voidcreateLink(ServerSession session, SftpSubsystemProxy subsystem, java.nio.file.Path link, java.nio.file.Path existing, boolean symLink)Invoked in order to create a link to a pathdefault java.nio.file.DirectoryStream<java.nio.file.Path>openDirectory(ServerSession session, SftpSubsystemProxy subsystem, DirectoryHandle dirHandle, java.nio.file.Path dir, java.lang.String handle)Called when a new directory stream is requesteddefault java.nio.channels.SeekableByteChannelopenFile(ServerSession session, SftpSubsystemProxy subsystem, FileHandle fileHandle, java.nio.file.Path file, java.lang.String handle, java.util.Set<? extends java.nio.file.OpenOption> options, java.nio.file.attribute.FileAttribute<?>... attrs)Called whenever a new file is openeddefault java.util.Map<java.lang.String,?>readFileAttributes(ServerSession session, SftpSubsystemProxy subsystem, java.nio.file.Path file, java.lang.String view, java.nio.file.LinkOption... options)Invoked when required to retrieve file attributes for a specific file system viewdefault voidremoveFile(ServerSession session, SftpSubsystemProxy subsystem, java.nio.file.Path path, boolean isDirectory)default voidrenameFile(ServerSession session, SftpSubsystemProxy subsystem, java.nio.file.Path oldPath, java.nio.file.Path newPath, java.util.Collection<java.nio.file.CopyOption> opts)default java.nio.file.attribute.UserPrincipalresolveFileOwner(ServerSession session, SftpSubsystemProxy subsystem, java.nio.file.Path file, java.nio.file.attribute.UserPrincipal name)default java.nio.file.attribute.GroupPrincipalresolveGroupOwner(ServerSession session, SftpSubsystemProxy subsystem, java.nio.file.Path file, java.nio.file.attribute.GroupPrincipal name)default java.lang.StringresolveLinkTarget(ServerSession session, SftpSubsystemProxy subsystem, java.nio.file.Path link)default java.nio.file.PathresolveLocalFilePath(ServerSession session, SftpSubsystemProxy subsystem, java.nio.file.Path rootDir, java.lang.String remotePath)Invoked in order to resolve remote file paths reference by the client into ones accessible by the serverdefault voidsetFileAccessControl(ServerSession session, SftpSubsystemProxy subsystem, java.nio.file.Path file, java.util.List<java.nio.file.attribute.AclEntry> acl, java.nio.file.LinkOption... options)default voidsetFileAttribute(ServerSession session, SftpSubsystemProxy subsystem, java.nio.file.Path file, java.lang.String view, java.lang.String attribute, java.lang.Object value, java.nio.file.LinkOption... options)Sets a view attribute for a local filedefault voidsetFileOwner(ServerSession session, SftpSubsystemProxy subsystem, java.nio.file.Path file, java.security.Principal value, java.nio.file.LinkOption... options)default voidsetFilePermissions(ServerSession session, SftpSubsystemProxy subsystem, java.nio.file.Path file, java.util.Set<java.nio.file.attribute.PosixFilePermission> perms, java.nio.file.LinkOption... options)default voidsetGroupOwner(ServerSession session, SftpSubsystemProxy subsystem, java.nio.file.Path file, java.security.Principal value, java.nio.file.LinkOption... options)default voidsyncFileData(ServerSession session, SftpSubsystemProxy subsystem, FileHandle fileHandle, java.nio.file.Path file, java.lang.String handle, java.nio.channels.Channel channel)Called when file meta-data re-synchronization is requireddefault java.nio.channels.FileLocktryLock(ServerSession session, SftpSubsystemProxy subsystem, FileHandle fileHandle, java.nio.file.Path file, java.lang.String handle, java.nio.channels.Channel channel, long position, long size, boolean shared)Called when locking a section of a file is requested
-
-
-
Field Detail
-
DEFAULT_UNIX_VIEW
static final java.util.List<java.lang.String> DEFAULT_UNIX_VIEW
-
FILEATTRS_RESOLVERS
static final java.util.NavigableMap<java.lang.String,FileInfoExtractor<?>> FILEATTRS_RESOLVERS
A case insensitiveNavigableMapofFileInfoExtractors 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
static final java.lang.String PROP_AUTO_SYNC_FILE_ON_CLOSE
Whether to invokeFileChannel.force(boolean)on files open for write when closing- See Also:
- Constant Field Values
-
DEFAULT_AUTO_SYNC_FILE_ON_CLOSE
static final boolean DEFAULT_AUTO_SYNC_FILE_ON_CLOSE
Default value for "sftp-auto-fsync-on-close" if none set- See Also:
- Constant Field Values
-
DEFAULT
static final SftpFileSystemAccessor DEFAULT
-
-
Method Detail
-
resolveLocalFilePath
default java.nio.file.Path resolveLocalFilePath(ServerSession session, SftpSubsystemProxy subsystem, java.nio.file.Path rootDir, java.lang.String remotePath) throws java.io.IOException, java.nio.file.InvalidPathException
Invoked in order to resolve remote file paths reference by the client into ones accessible by the server- Parameters:
session- TheServerSessionthrough 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. thechrootlocationremotePath- The remote path - separated by '/'- Returns:
- The local
Path - Throws:
java.io.IOException- If failed to resolve the local pathjava.nio.file.InvalidPathException- If bad local path specification- See Also:
SftpSubsystemEnvironment#getDefaultDirectory()
-
openFile
default java.nio.channels.SeekableByteChannel openFile(ServerSession session, SftpSubsystemProxy subsystem, FileHandle fileHandle, java.nio.file.Path file, java.lang.String handle, java.util.Set<? extends java.nio.file.OpenOption> options, java.nio.file.attribute.FileAttribute<?>... attrs) throws java.io.IOException
Called whenever a new file is opened- Parameters:
session- TheServerSessionthrough which the request was receivedsubsystem- The SFTP subsystem instance that manages the sessionfileHandle- TheFileHandlerepresenting the created channel - may benullif not invoked within the context of such a handle (special cases)file- The requested local filePath- same one returned byresolveLocalFilePathhandle- 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 requestedOpenOptionsattrs- The requestedFileAttributes- Returns:
- The opened
SeekableByteChannel - Throws:
java.io.IOException- If failed to open
-
tryLock
default java.nio.channels.FileLock tryLock(ServerSession session, SftpSubsystemProxy subsystem, FileHandle fileHandle, java.nio.file.Path file, java.lang.String handle, java.nio.channels.Channel channel, long position, long size, boolean shared) throws java.io.IOException
Called when locking a section of a file is requested- Parameters:
session- TheServerSessionthrough which the request was receivedsubsystem- The SFTP subsystem instance that manages the sessionfileHandle- TheFileHandlerepresenting the created channelfile- The requested local filePath- same one returned byresolveLocalFilePathhandle- The assigned file handle through which the remote peer references this filechannel- The originalChannelthat 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-trueto request a shared lock,falseto request an exclusive lock- Returns:
- A lock object representing the newly-acquired lock, or
nullif the lock could not be acquired because another program holds an overlapping lock - Throws:
java.io.IOException- If failed to honor the request- See Also:
FileChannel.tryLock(long, long, boolean)
-
syncFileData
default void syncFileData(ServerSession session, SftpSubsystemProxy subsystem, FileHandle fileHandle, java.nio.file.Path file, java.lang.String handle, java.nio.channels.Channel channel) throws java.io.IOException
Called when file meta-data re-synchronization is required- Parameters:
session- TheServerSessionthrough which the request was receivedsubsystem- The SFTP subsystem instance that manages the sessionfileHandle- TheFileHandlerepresenting the created channelfile- The requested local filePath- same one returned byresolveLocalFilePathhandle- The assigned file handle through which the remote peer references this filechannel- The originalChannelthat was returned byopenFile(ServerSession, SftpSubsystemProxy, FileHandle, Path, String, Set, FileAttribute...)- Throws:
java.io.IOException- If failed to execute the request- See Also:
FileChannel.force(boolean), OpenSSH - section 10
-
closeFile
default void closeFile(ServerSession session, SftpSubsystemProxy subsystem, FileHandle fileHandle, java.nio.file.Path file, java.lang.String handle, java.nio.channels.Channel channel, java.util.Set<? extends java.nio.file.OpenOption> options) throws java.io.IOException
Called to inform the accessor that it should close the file- Parameters:
session- TheServerSessionthrough which the request was receivedsubsystem- The SFTP subsystem instance that manages the sessionfileHandle- TheFileHandlerepresenting the created channel - may benullif not invoked within the context of such a handle (special cases)file- The requested local filePath- same one returned byresolveLocalFilePathhandle- The assigned file handle through which the remote peer references this filechannel- The originalChannelthat was returned byopenFile(ServerSession, SftpSubsystemProxy, FileHandle, Path, String, Set, FileAttribute...)options- The original options used to open the channel- Throws:
java.io.IOException- If failed to execute the request
-
openDirectory
default java.nio.file.DirectoryStream<java.nio.file.Path> openDirectory(ServerSession session, SftpSubsystemProxy subsystem, DirectoryHandle dirHandle, java.nio.file.Path dir, java.lang.String handle) throws java.io.IOException
Called when a new directory stream is requested- Parameters:
session- TheServerSessionthrough which the request was receivedsubsystem- The SFTP subsystem instance that manages the sessiondirHandle- TheDirectoryHandlerepresenting the streamdir- The requested local directoryPath- same one returned byresolveLocalFilePathhandle- The assigned directory handle through which the remote peer references this directory- Returns:
- The opened
DirectoryStream - Throws:
java.io.IOException- If failed to open
-
closeDirectory
default void closeDirectory(ServerSession session, SftpSubsystemProxy subsystem, DirectoryHandle dirHandle, java.nio.file.Path dir, java.lang.String handle, java.nio.file.DirectoryStream<java.nio.file.Path> ds) throws java.io.IOException
Called when a directory stream is no longer required- Parameters:
session- TheServerSessionthrough which the request was receivedsubsystem- The SFTP subsystem instance that manages the sessiondirHandle- TheDirectoryHandlerepresenting the stream - may benullif not invoked within the context of such a handle (special cases)dir- The requested local directoryPath- same one returned byresolveLocalFilePathhandle- The assigned directory handle through which the remote peer references this directoryds- The disposedDirectoryStream- Throws:
java.io.IOException- If failed to open
-
readFileAttributes
default java.util.Map<java.lang.String,?> readFileAttributes(ServerSession session, SftpSubsystemProxy subsystem, java.nio.file.Path file, java.lang.String view, java.nio.file.LinkOption... options) throws java.io.IOException
Invoked when required to retrieve file attributes for a specific file system view- Parameters:
session- TheServerSessionthrough which the request was receivedsubsystem- The SFTP subsystem instance that manages the sessionfile- The requested local filePath- same one returned byresolveLocalFilePathview- The required view nameoptions- The accessLinkOption-s- Returns:
- A
Mapof all the attributes available for the file in the view - Throws:
java.io.IOException- If failed to read the attributes- See Also:
Files.readAttributes(Path, String, LinkOption...)
-
setFileAttribute
default void setFileAttribute(ServerSession session, SftpSubsystemProxy subsystem, java.nio.file.Path file, java.lang.String view, java.lang.String attribute, java.lang.Object value, java.nio.file.LinkOption... options) throws java.io.IOException
Sets a view attribute for a local file- Parameters:
session- TheServerSessionthrough which the request was receivedsubsystem- The SFTP subsystem instance that manages the sessionfile- The requested local filePath- same one returned byresolveLocalFilePathview- The required view nameattribute- The attribute namevalue- The attribute valueoptions- The accessLinkOption-s- Throws:
java.io.IOException- If failed to set the attribute
-
resolveFileOwner
default java.nio.file.attribute.UserPrincipal resolveFileOwner(ServerSession session, SftpSubsystemProxy subsystem, java.nio.file.Path file, java.nio.file.attribute.UserPrincipal name) throws java.io.IOException
- Throws:
java.io.IOException
-
setFileOwner
default void setFileOwner(ServerSession session, SftpSubsystemProxy subsystem, java.nio.file.Path file, java.security.Principal value, java.nio.file.LinkOption... options) throws java.io.IOException
- Throws:
java.io.IOException
-
resolveGroupOwner
default java.nio.file.attribute.GroupPrincipal resolveGroupOwner(ServerSession session, SftpSubsystemProxy subsystem, java.nio.file.Path file, java.nio.file.attribute.GroupPrincipal name) throws java.io.IOException
- Throws:
java.io.IOException
-
setGroupOwner
default void setGroupOwner(ServerSession session, SftpSubsystemProxy subsystem, java.nio.file.Path file, java.security.Principal value, java.nio.file.LinkOption... options) throws java.io.IOException
- Throws:
java.io.IOException
-
setFilePermissions
default void setFilePermissions(ServerSession session, SftpSubsystemProxy subsystem, java.nio.file.Path file, java.util.Set<java.nio.file.attribute.PosixFilePermission> perms, java.nio.file.LinkOption... options) throws java.io.IOException
- Throws:
java.io.IOException
-
setFileAccessControl
default void setFileAccessControl(ServerSession session, SftpSubsystemProxy subsystem, java.nio.file.Path file, java.util.List<java.nio.file.attribute.AclEntry> acl, java.nio.file.LinkOption... options) throws java.io.IOException
- Throws:
java.io.IOException
-
createDirectory
default void createDirectory(ServerSession session, SftpSubsystemProxy subsystem, java.nio.file.Path path) throws java.io.IOException
- Throws:
java.io.IOException
-
createLink
default void createLink(ServerSession session, SftpSubsystemProxy subsystem, java.nio.file.Path link, java.nio.file.Path existing, boolean symLink) throws java.io.IOException
Invoked in order to create a link to a path- Parameters:
session- TheServerSessionthrough which the request was receivedsubsystem- The SFTP subsystem instance that manages the sessionlink- The requested linkPath- same one returned byresolveLocalFilePathexisting- The existingPaththat the link should referencesymLink-trueif this should be a symbolic link- Throws:
java.io.IOException- If failed to create the link- See Also:
Files.createLink(Path, Path),Files.createSymbolicLink(Path, Path, FileAttribute...)
-
resolveLinkTarget
default java.lang.String resolveLinkTarget(ServerSession session, SftpSubsystemProxy subsystem, java.nio.file.Path link) throws java.io.IOException
- Throws:
java.io.IOException
-
renameFile
default void renameFile(ServerSession session, SftpSubsystemProxy subsystem, java.nio.file.Path oldPath, java.nio.file.Path newPath, java.util.Collection<java.nio.file.CopyOption> opts) throws java.io.IOException
- Throws:
java.io.IOException
-
copyFile
default void copyFile(ServerSession session, SftpSubsystemProxy subsystem, java.nio.file.Path src, java.nio.file.Path dst, java.util.Collection<java.nio.file.CopyOption> opts) throws java.io.IOException
- Throws:
java.io.IOException
-
removeFile
default void removeFile(ServerSession session, SftpSubsystemProxy subsystem, java.nio.file.Path path, boolean isDirectory) throws java.io.IOException
- Throws:
java.io.IOException
-
-