Package org.apache.sshd.sftp.server
Interface SftpFileSystemAccessor
-
public interface SftpFileSystemAccessor- Author:
- Apache MINA SSHD Project
-
-
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 List<String>DEFAULT_UNIX_VIEWstatic NavigableMap<String,org.apache.sshd.common.util.io.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 StringPROP_AUTO_SYNC_FILE_ON_CLOSEWhether to invokeFileChannel.force(boolean)on files open for write when closing
-
Method Summary
All Methods Static Methods Instance Methods Default Methods Modifier and Type Method Description default voidapplyExtensionFileAttributes(SftpSubsystemProxy subsystem, Path file, Map<String,byte[]> extensions, LinkOption... options)Invoked in order to allow processing of custom file attributesdefault voidcloseDirectory(SftpSubsystemProxy subsystem, DirectoryHandle dirHandle, Path dir, String handle, DirectoryStream<Path> ds)Called when a directory stream is no longer requireddefault voidcloseFile(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 voidcopyFile(SftpSubsystemProxy subsystem, Path src, Path dst, Collection<CopyOption> opts)default voidcreateDirectory(SftpSubsystemProxy subsystem, Path path)default voidcreateLink(SftpSubsystemProxy subsystem, Path link, Path existing, boolean symLink)Invoked in order to create a link to a pathdefault booleannoFollow(Collection<?> opts)default DirectoryStream<Path>openDirectory(SftpSubsystemProxy subsystem, DirectoryHandle dirHandle, Path dir, String handle, LinkOption... linkOptions)Called when a new directory stream is requesteddefault SeekableByteChannelopenFile(SftpSubsystemProxy subsystem, FileHandle fileHandle, Path file, String handle, Set<? extends OpenOption> options, FileAttribute<?>... attrs)Called whenever a new file is openeddefault voidputRemoteFileName(SftpSubsystemProxy subsystem, Path path, org.apache.sshd.common.util.buffer.Buffer buf, String name, boolean shortName)Invoked in order to encode the outgoing referenced file name/pathdefault Map<String,?>readFileAttributes(SftpSubsystemProxy subsystem, Path file, String view, LinkOption... options)Invoked when required to retrieve file attributes for a specific file system viewdefault voidremoveFile(SftpSubsystemProxy subsystem, Path path, boolean isDirectory)default voidrenameFile(SftpSubsystemProxy subsystem, Path oldPath, Path newPath, Collection<CopyOption> opts)default LinkOption[]resolveFileAccessLinkOptions(SftpSubsystemProxy subsystem, Path file, int cmd, String extension, boolean followLinks)Invoked in order to determine the symbolic link follow optionsdefault UserPrincipalresolveFileOwner(SftpSubsystemProxy subsystem, Path file, UserPrincipal name)default GroupPrincipalresolveGroupOwner(SftpSubsystemProxy subsystem, Path file, GroupPrincipal name)default StringresolveLinkTarget(SftpSubsystemProxy subsystem, Path link)default PathresolveLocalFilePath(SftpSubsystemProxy subsystem, Path rootDir, String remotePath)Invoked in order to resolve remote file paths reference by the client into ones accessible by the serverdefault NavigableMap<String,Object>resolveReportedFileAttributes(SftpSubsystemProxy subsystem, Path file, int flags, NavigableMap<String,Object> attrs, LinkOption... options)Invoked in order to allow intervention to the reported file attributes - e.g., add custom/extended propertiesstatic SecureDirectoryStream<Path>secure(DirectoryStream<Path> ds)static SecureDirectoryStream<Path>secureResolveDirectoryStream(Path toResolve)static SeekableByteChannelseekableByteChannelNoLinkFollow(Path src, Set<? extends OpenOption> opts, FileAttribute<?>... fileAttributes)default voidsetFileAccessControl(SftpSubsystemProxy subsystem, Path file, List<AclEntry> acl, LinkOption... options)default voidsetFileAttribute(SftpSubsystemProxy subsystem, Path file, String view, String attribute, Object value, LinkOption... options)Sets a view attribute for a local filedefault voidsetFileOwner(SftpSubsystemProxy subsystem, Path file, Principal value, LinkOption... options)default voidsetFilePermissions(SftpSubsystemProxy subsystem, Path file, Set<PosixFilePermission> perms, LinkOption... options)default voidsetGroupOwner(SftpSubsystemProxy subsystem, Path file, Principal value, LinkOption... options)default voidsyncFileData(SftpSubsystemProxy subsystem, FileHandle fileHandle, Path file, String handle, Channel channel)Called when file meta-data re-synchronization is requireddefault FileLocktryLock(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 Detail
-
FILEATTRS_RESOLVERS
static final NavigableMap<String,org.apache.sshd.common.util.io.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 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 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- 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:
IOException- If failed to resolve the local pathInvalidPathException- If bad local path specification- See Also:
SftpSubsystemEnvironment#getDefaultDirectory()
-
resolveFileAccessLinkOptions
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- The SFTP subsystem instance that manages the sessionfile- The referenced filecmd- The SFTP command that triggered this accessextension- The SFTP extension that triggered this access - non-empty only for {SSH_FXP_EXTENDED} commandfollowLinks- Whether to follow symbolic links- Returns:
- The
LinkOption-s to use - invokesIoUtils.getLinkOptions(boolean)by default - Throws:
IOException- if failed to resolve the required options- See Also:
- SSHD-1137
-
resolveReportedFileAttributes
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- The SFTP subsystem instance that manages the sessionfile- The referenced fileflags- A mask of the original required attributesattrs- The default resolved attributes mapoptions- TheLinkOption-s that were used to access the file's attributes- Returns:
- The updated attributes map
- Throws:
IOException- If failed to resolve the attributes- See Also:
- SSHD-1226
-
applyExtensionFileAttributes
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- The SFTP subsystem instance that manages the sessionfile- The referenced fileextensions- The received extensions - may benull/emptyoptions- TheLinkOption-s that were used to access the file's standard attributes- Throws:
IOException- If failed to apply the attributes
-
putRemoteFileName
default void putRemoteFileName(SftpSubsystemProxy subsystem, Path path, org.apache.sshd.common.util.buffer.Buffer buf, String name, boolean shortName) throws IOException
Invoked in order to encode the outgoing referenced file name/path- Parameters:
subsystem- The SFTP subsystem instance that manages the sessionpath- The associated filePath- Note: might be a symbolic link containerbuf- The targetBufferfor the encoded stringname- The string to sendshortName- Iftruethen this is the "pure" file name/path, otherwise it also contains user/group/size/last-modified-time/etc.- Throws:
IOException- If failed to resolve the remote name- See Also:
- SSHD-1132
-
openFile
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- 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:
IOException- If failed to open
-
tryLock
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- 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(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:
IOException- If failed to honor the request- See Also:
FileChannel.tryLock(long, long, boolean)
-
syncFileData
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- 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(SftpSubsystemProxy, FileHandle, Path, String, Set, FileAttribute...)- Throws:
IOException- If failed to execute the request- See Also:
FileChannel.force(boolean), OpenSSH - section 10
-
closeFile
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- 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(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(SftpSubsystemProxy subsystem, DirectoryHandle dirHandle, Path dir, String handle, LinkOption... linkOptions) throws IOException
Called when a new directory stream is requested- Parameters:
subsystem- 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 directorylinkOptions- TheLinkOptions - OK ifnull/empty.- Returns:
- The opened
DirectoryStream - Throws:
IOException- If failed to open
-
closeDirectory
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- 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:
IOException- If failed to open
-
readFileAttributes
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- 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:
IOException- If failed to read the attributes- See Also:
Files.readAttributes(Path, String, LinkOption...)
-
setFileAttribute
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- 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:
IOException- If failed to set the attribute
-
resolveFileOwner
default UserPrincipal resolveFileOwner(SftpSubsystemProxy subsystem, Path file, UserPrincipal name) throws IOException
- Throws:
IOException
-
setFileOwner
default void setFileOwner(SftpSubsystemProxy subsystem, Path file, Principal value, LinkOption... options) throws IOException
- Throws:
IOException
-
resolveGroupOwner
default GroupPrincipal resolveGroupOwner(SftpSubsystemProxy subsystem, Path file, GroupPrincipal name) throws IOException
- Throws:
IOException
-
setGroupOwner
default void setGroupOwner(SftpSubsystemProxy subsystem, Path file, Principal value, LinkOption... options) throws IOException
- Throws:
IOException
-
setFilePermissions
default void setFilePermissions(SftpSubsystemProxy subsystem, Path file, Set<PosixFilePermission> perms, LinkOption... options) throws IOException
- Throws:
IOException
-
setFileAccessControl
default void setFileAccessControl(SftpSubsystemProxy subsystem, Path file, List<AclEntry> acl, LinkOption... options) throws IOException
- Throws:
IOException
-
createDirectory
default void createDirectory(SftpSubsystemProxy subsystem, Path path) throws IOException
- Throws:
IOException
-
createLink
default void createLink(SftpSubsystemProxy subsystem, Path link, Path existing, boolean symLink) throws IOException
Invoked in order to create a link to a path- Parameters:
subsystem- 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:
IOException- If failed to create the link- See Also:
Files.createLink(Path, Path),Files.createSymbolicLink(Path, Path, FileAttribute...)
-
resolveLinkTarget
default String resolveLinkTarget(SftpSubsystemProxy subsystem, Path link) throws IOException
- Throws:
IOException
-
renameFile
default void renameFile(SftpSubsystemProxy subsystem, Path oldPath, Path newPath, Collection<CopyOption> opts) throws IOException
- Throws:
IOException
-
copyFile
default void copyFile(SftpSubsystemProxy subsystem, Path src, Path dst, Collection<CopyOption> opts) throws IOException
- Throws:
IOException
-
seekableByteChannelNoLinkFollow
static SeekableByteChannel seekableByteChannelNoLinkFollow(Path src, Set<? extends OpenOption> opts, FileAttribute<?>... fileAttributes) throws IOException
- Throws:
IOException
-
secureResolveDirectoryStream
static SecureDirectoryStream<Path> secureResolveDirectoryStream(Path toResolve) throws IOException
- Throws:
IOException
-
secure
static SecureDirectoryStream<Path> secure(DirectoryStream<Path> ds)
-
removeFile
default void removeFile(SftpSubsystemProxy subsystem, Path path, boolean isDirectory) throws IOException
- Throws:
IOException
-
noFollow
default boolean noFollow(Collection<?> opts)
-
-