Package org.apache.sshd.sftp.server
Class AbstractSftpSubsystemHelper
java.lang.Object
org.apache.sshd.common.util.logging.AbstractLoggingBean
org.apache.sshd.sftp.server.AbstractSftpSubsystemHelper
- All Implemented Interfaces:
SessionContextHolder,SessionHolder<ServerSession>,ServerChannelSessionHolder,ServerSessionHolder,SftpErrorStatusDataHandlerProvider,SftpEventListenerManager,SftpFileSystemAccessorProvider,SftpSubsystemEnvironment,SftpSubsystemProxy,SftpUnsupportedAttributePolicyProvider
- Direct Known Subclasses:
SftpSubsystem
public abstract class AbstractSftpSubsystemHelper
extends AbstractLoggingBean
implements SftpSubsystemProxy
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ChannelSessionstatic final List<AbstractOpenSSHExtensionParser.OpenSSHExtension> static final NavigableMap<String, OptionalFeature> The default reported supported client extensions (case insensitive)private final SftpErrorStatusDataHandlerprivate final SftpFileSystemAccessorprivate final SftpEventListenerprivate final Collection<SftpEventListener> private final UnsupportedAttributePolicyFields inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
logFields inherited from interface org.apache.sshd.sftp.server.SftpSubsystemEnvironment
ALL_SFTP_IMPL, HIGHER_SFTP_IMPL, LOWER_SFTP_IMPL, SUPPORTED_SFTP_VERSIONS -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractSftpSubsystemHelper(ChannelSession channelSession, SftpSubsystemConfigurator configurator) -
Method Summary
Modifier and TypeMethodDescriptionprotected NavigableMap<String, Object> addMissingAttribute(Path file, NavigableMap<String, Object> current, String name, FileInfoExtractor<?> x, LinkOption... options) booleanaddSftpEventListener(SftpEventListener listener) Register a listener instanceprotected intappendAclSupportedExtension(Buffer buffer, ServerSession session) protected voidappendExtensions(Buffer buffer, String supportedVersions) protected StringappendNewlineExtension(Buffer buffer, ServerSession session) Appends the "newline" extension to the buffer.appendOpenSSHExtensions(Buffer buffer, ServerSession session) protected voidappendSupported2Extension(Buffer buffer, Collection<String> extras) Appends the "supported2" extension to the buffer.protected voidappendSupportedExtension(Buffer buffer, Collection<String> extras) Appends the "supported" extension to the buffer.appendVendorIdExtension(Buffer buffer, Map<String, ?> versionProperties, ServerSession session) Appends the "vendor-id" extension to the buffer.protected StringappendVersionsExtension(Buffer buffer, String value, ServerSession session) Appends the "versions" extension to the buffer.checkSymlinkState(Path path, boolean neverFollowSymLinks, LinkOption[] options) A utility function to validate that the directories leading up to a file are not symlinkscheckVersionCompatibility(Buffer buffer, int id, int proposed, int failureOpcode) Checks if a proposed version is within supported range.protected abstract voidcreateLink(int id, String existingPath, String linkPath, boolean symLink) protected abstract voidprotected voidprotected abstract voiddoCheckFileHash(int id, String targetType, String target, Collection<String> algos, long startOffset, long length, int blockSize, Buffer buffer) protected voiddoCheckFileHash(int id, Path file, NamedFactory<? extends Digest> factory, long startOffset, long length, int blockSize, Buffer buffer) protected voiddoCheckFileHash(Buffer buffer, int id, String targetType) protected abstract voidprotected voidprotected abstract voiddoCopyData(int id, String readHandle, long readOffset, long readLength, String writeHandle, long writeOffset) protected voiddoCopyData(Buffer buffer, int id) protected voiddoCopyFile(int id, String srcFile, String dstFile, boolean overwriteDestination) protected voiddoCopyFile(int id, String srcFile, String dstFile, Collection<CopyOption> opts) protected voiddoCopyFile(Buffer buffer, int id) protected voiddoExtended(Buffer buffer, int id) protected abstract voiddoFSetStat(int id, String handle, Map<String, ?> attrs) protected voiddoFSetStat(Buffer buffer, int id) protected voidprotected abstract voidprotected voidprotected voidprotected voidprotected voiddoMakeDirectory(int id, String path, Map<String, ?> attrs) protected voiddoMakeDirectory(Buffer buffer, int id) protected abstract byte[]doMD5Hash(int id, String targetType, String target, long startOffset, long length, byte[] quickCheckHash) protected byte[]protected voidprotected abstract Stringprotected voidprotected abstract StringdoOpenDir(int id, String path, Path p, LinkOption... options) protected voidprotected abstract voiddoOpenSSHFsync(int id, String handle) protected voiddoOpenSSHFsync(Buffer buffer, int id) protected voiddoOpenSSHHardLink(int id, String srcFile, String dstFile) protected voiddoOpenSSHHardLink(Buffer buffer, int id) protected voiddoOpenSSHLimits(Buffer buffer, int id) protected voiddoPosixRename(Buffer buffer, int id) protected voidprotected abstract intdoRead(int id, String handle, long offset, int length, byte[] data, int doff, AtomicReference<Boolean> eof) protected voidprotected intdoReadDir(int id, String handle, DirectoryHandle dir, Buffer buffer, int maxSize, boolean followLinks) protected abstract voidprotected AbstractMap.SimpleImmutableEntry<Path, String> doReadLink(int id, String path) protected voiddoReadLink(Buffer buffer, int id) protected voiddoRealPath(Buffer buffer, int id) protected AbstractMap.SimpleImmutableEntry<Path, Boolean> doRealPathV345(int id, String path, Path p, LinkOption... options) protected AbstractMap.SimpleImmutableEntry<Path, Boolean> doRealPathV6(int id, String path, Collection<String> extraPaths, Path p, LinkOption... options) protected voidCalled when need to delete a file / directory - also informs theSftpEventListenerprotected voidprotected voiddoRemoveDirectory(int id, String path) protected voiddoRemoveDirectory(Buffer buffer, int id) protected voiddoRemoveFile(int id, String path) protected voidprotected voiddoRename(int id, String oldPath, String newPath, Collection<CopyOption> opts) protected voidprotected voiddoSetAttributes(int cmd, String extension, Path file, Map<String, ?> attributes, boolean followLinks) protected voidprotected voidprotected SpaceAvailableExtensionInfodoSpaceAvailable(int id, String path) protected voiddoSpaceAvailable(Buffer buffer, int id) protected voidprotected voidprotected voidprotected abstract voiddoTextSeek(int id, String handle, long line) protected voiddoTextSeek(Buffer buffer, int id) protected abstract voidprotected voidprotected voiddoUnsupported(Buffer buffer, int length, int type, int id) protected voiddoUnsupportedExtension(Buffer buffer, int id, String extension) protected voiddoVersionSelect(Buffer buffer, int id) protected abstract voiddoVersionSelect(Buffer buffer, int id, String proposed) protected abstract voidprotected voidprotected voidexecuteExtendedCommand(Buffer buffer, int id, String extension) protected NavigableMap<String, Object> getAttributes(Path path, int flags, LinkOption... options) protected NavigableMap<String, Object> getAttributes(Path file, LinkOption... options) protected StringgetLongName(Path f, String shortName, boolean sendAttrs, LinkOption... options) protected StringgetLongName(Path f, String shortName, LinkOption... options) protected StringgetLongName(Path f, String shortName, Map<String, ?> attributes) protected StringgetLongName(Path f, String shortName, SftpClient.Attributes attributes) protected OpenSSHLimitsExtensionInfogetOpenSSHLimitsExtensionInfo(int id, ChannelSession channel) protected LinkOption[]getPathResolutionLinkOption(int cmd, String extension, Path path) protected StringgetShortName(Path f) protected Map<String, OptionalFeature> protected NavigableMap<String, Object> handleReadFileAttributesException(Path file, String view, LinkOption[] options, IOException e) protected voidhandleSetFileAttributeFailure(Path file, String view, String attribute, Object value, Collection<String> unsupported, Exception e) protected NavigableMap<String, Object> handleUnknownStatusFileAttributes(Path file, int flags, LinkOption... options) protected voidhandleUnsupportedAttributes(Collection<String> attributes) protected voidhandleUserPrincipalLookupServiceException(Class<? extends Principal> principalType, String name, IOException e) protected Pathprotected abstract BufferprepareReply(Buffer buffer) protected voidProcess an SFTP command.protected NavigableMap<String, Object> readFileAttributes(Path file, String view, LinkOption... options) booleanremoveSftpEventListener(SftpEventListener listener) Remove a listener instanceprotected Collection<Integer> protected PathresolveFile(String remotePath) protected NavigableMap<String, Object> resolveFileAttributes(Path path, int flags, boolean neverFollowSymLinks, LinkOption... options) protected NavigableMap<String, Object> resolveMissingFileAttributes(Path file, int flags, Map<String, Object> current, LinkOption... options) Called bygetAttributes(Path, int, LinkOption...)in order to complete any attributes that could not be retrieved via the supported file system views.protected ObjectresolveMissingFileAttributeValue(Path file, String name, Object value, FileInfoExtractor<?> x, LinkOption... options) protected StringresolveNewlineValue(ServerSession session) protected PathresolveNormalizedLocation(String remotePath) resolveOpenSSHExtensions(ServerSession session) protected booleanresolvePathResolutionFollowLinks(int cmd, String extension, Path path) protected NavigableMap<String, Object> resolveReportedFileAttributes(Path file, int flags, LinkOption... options) protected abstract voidprotected voidprotected voidsendHandle(Buffer buffer, int id, String handle) protected voidprotected voidprotected voidsendStatus(Buffer buffer, int id, int substatus, String msg) protected voidsendStatus(Buffer buffer, int id, int substatus, String msg, String lang) protected voidsendStatus(Buffer buffer, int id, Throwable e, int cmd, Object... args) Invoked when an exception was thrown due to the execution of some SFTP commandprotected voidsetFileAccessControl(Path file, List<AclEntry> acl, LinkOption... options) protected voidsetFileAttribute(Path file, String view, String attribute, Object value, LinkOption... options) protected voidsetFileAttributes(Path file, Map<String, ?> attributes, LinkOption... options) protected voidsetFileExtensions(Path file, Map<String, byte[]> extensions, LinkOption... options) protected voidsetFileOwnership(Path file, String attribute, Principal value, LinkOption... options) protected voidsetFilePermissions(Path file, Set<PosixFilePermission> perms, LinkOption... options) protected voidsetFileRawViewAttribute(Path file, String view, String attribute, Object value, LinkOption... options) protected voidsetFileTime(Path file, String view, String attribute, FileTime value, LinkOption... options) protected <E extends IOException>
EsignalOpenFailure(int id, String pathValue, Path path, boolean isDir, E thrown) protected <E extends IOException>
EsignalRemovalPreConditionFailure(int id, String pathValue, Path path, E thrown, boolean isRemoveDirectory) protected GroupPrincipaltoGroup(Path file, GroupPrincipal name) protected UserPrincipaltoUser(Path file, UserPrincipal name) protected <H extends Handle>
HvalidateHandle(String handle, Handle h, Class<H> type) Makes sure that the local handle is not null and of the specified typevalidateParentExistWithNoSymlinksIfNeverFollowSymlinks(Path path, boolean neverFollowSymLinks) protected BooleanvalidateProposedVersion(Buffer buffer, int id, String proposal) protected AbstractMap.SimpleImmutableEntry<Path, Boolean> validateRealPath(int id, String path, Path f, LinkOption... options) protected voidwriteAttrs(Buffer buffer, Map<String, ?> attributes) protected voidwriteDirEntry(int id, DirectoryHandle dir, Map<String, Path> entries, Buffer buffer, int index, Path f, String shortName, LinkOption... options) protected voidwriteDirEntry(ServerSession session, int id, Buffer buffer, int index, Path f, String shortName, SftpClient.Attributes attributes) Methods inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
debug, debug, debug, debug, debug, error, error, error, error, error, getSimplifiedLogger, info, info, warn, warn, warn, warn, warn, warn, warn, warnMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.sshd.server.session.ServerSessionHolder
getServerSessionMethods inherited from interface org.apache.sshd.common.session.SessionHolder
getSessionContextMethods inherited from interface org.apache.sshd.sftp.server.SftpSubsystemEnvironment
getDefaultDirectory, getSession, getVersion
-
Field Details
-
DEFAULT_SUPPORTED_CLIENT_EXTENSIONS
The default reported supported client extensions (case insensitive) -
DEFAULT_OPEN_SSH_EXTENSIONS
public static final List<AbstractOpenSSHExtensionParser.OpenSSHExtension> DEFAULT_OPEN_SSH_EXTENSIONS -
DEFAULT_OPEN_SSH_EXTENSIONS_NAMES
-
DEFAULT_ACL_SUPPORTED_MASK
-
channelSession
-
unsupportedAttributePolicy
-
sftpEventListeners
-
sftpEventListenerProxy
-
fileSystemAccessor
-
errorStatusDataHandler
-
-
Constructor Details
-
AbstractSftpSubsystemHelper
protected AbstractSftpSubsystemHelper(ChannelSession channelSession, SftpSubsystemConfigurator configurator)
-
-
Method Details
-
getServerChannelSession
- Specified by:
getServerChannelSessionin interfaceServerChannelSessionHolder
-
getUnsupportedAttributePolicy
- Specified by:
getUnsupportedAttributePolicyin interfaceSftpUnsupportedAttributePolicyProvider- Returns:
- The
UnsupportedAttributePolicyto use if failed to access some local file attributes
-
getFileSystemAccessor
- Specified by:
getFileSystemAccessorin interfaceSftpFileSystemAccessorProvider- Returns:
- The
SftpFileSystemAccessorto use for accessing files and directories
-
getSftpEventListenerProxy
- Specified by:
getSftpEventListenerProxyin interfaceSftpEventListenerManager- Returns:
- An instance representing all the currently registered listeners. Any method invocation is replicated to the actually registered listeners
-
addSftpEventListener
Description copied from interface:SftpEventListenerManagerRegister a listener instance- Specified by:
addSftpEventListenerin interfaceSftpEventListenerManager- Parameters:
listener- TheSftpEventListenerinstance to add - nevernull- Returns:
trueif listener is a previously un-registered one
-
removeSftpEventListener
Description copied from interface:SftpEventListenerManagerRemove a listener instance- Specified by:
removeSftpEventListenerin interfaceSftpEventListenerManager- Parameters:
listener- TheSftpEventListenerinstance to remove - nevernull- Returns:
trueif listener is a (removed) registered one
-
getErrorStatusDataHandler
- Specified by:
getErrorStatusDataHandlerin interfaceSftpErrorStatusDataHandlerProvider- Returns:
- The (never
null)SftpErrorStatusDataHandlerto use when generating failed commands error messages
-
validateProposedVersion
protected Boolean validateProposedVersion(Buffer buffer, int id, String proposal) throws IOException - Parameters:
buffer- TheBufferholding the requestid- The request idproposal- The proposed value- Returns:
- A
Booleanindicating whether to accept/reject the proposal. Ifnullthen rejection response has been sent, otherwise and appropriate response is generated - Throws:
IOException- If failed send an independent rejection response
-
checkVersionCompatibility
protected Map.Entry<Integer,String> checkVersionCompatibility(Buffer buffer, int id, int proposed, int failureOpcode) throws IOException Checks if a proposed version is within supported range. Note: if the user forced a specific value via theSftpModuleProperties.SFTP_VERSIONproperty, then it is used to validate the proposed value- Parameters:
buffer- TheBuffercontaining the requestid- The SSH message ID to be used to send the failure message if requiredproposed- The proposed version valuefailureOpcode- The failure opcode to send if validation fails- Returns:
- A "pair" whose key is the negotiated version and value a
Stringof comma separated values representing all the supported versions.nullif validation failed and an appropriate status message was sent - Throws:
IOException- If failed to send the failure status message
-
process
Process an SFTP command. If the command throws an exception, the channel will be closed.- Parameters:
buffer- the buffer to process- Throws:
IOException- if anything wrong happens
-
doProcess
- Throws:
IOException
-
doUnsupported
- Throws:
IOException
-
doInit
- Throws:
IOException
-
doVersionSelect
- Throws:
IOException
-
doVersionSelect
- Throws:
IOException
-
doOpen
- Throws:
IOException
-
doOpen
protected abstract String doOpen(int id, String path, int pflags, int access, Map<String, Object> attrs) throws IOException- Parameters:
id- Request idpath- Pathpflags- Open mode flags - seeSSH_FXF_XXXflagsaccess- Access mode flags - seeACE4_XXXflagsattrs- Requested attributes- Returns:
- The assigned (opaque) handle
- Throws:
IOException- if failed to execute
-
signalOpenFailure
protected <E extends IOException> E signalOpenFailure(int id, String pathValue, Path path, boolean isDir, E thrown) throws IOException - Throws:
IOException
-
doClose
- Throws:
IOException
-
doClose
- Throws:
IOException
-
doRead
- Throws:
IOException
-
doRead
protected abstract int doRead(int id, String handle, long offset, int length, byte[] data, int doff, AtomicReference<Boolean> eof) throws IOException - Throws:
IOException
-
doWrite
- Throws:
IOException
-
doWrite
protected abstract void doWrite(int id, String handle, long offset, int length, byte[] data, int doff, int remaining) throws IOException - Throws:
IOException
-
doLStat
- Throws:
IOException
-
doLStat
- Throws:
IOException
-
doSetStat
protected void doSetStat(Buffer buffer, int id, String extension, int cmd, Boolean followLinks) throws IOException - Throws:
IOException
-
doSetStat
protected void doSetStat(int id, String path, int cmd, String extension, Map<String, ?> attrs, Boolean followLinks) throws IOException- Throws:
IOException
-
doFStat
- Throws:
IOException
-
doFStat
- Throws:
IOException
-
doFSetStat
- Throws:
IOException
-
doFSetStat
- Throws:
IOException
-
doOpenDir
- Throws:
IOException
-
doOpenDir
protected abstract String doOpenDir(int id, String path, Path p, LinkOption... options) throws IOException - Throws:
IOException
-
doReadDir
- Throws:
IOException
-
doLink
- Throws:
IOException
-
doLink
protected void doLink(int id, String targetPath, String linkPath, boolean symLink) throws IOException - Throws:
IOException
-
doSymLink
- Throws:
IOException
-
doSymLink
- Throws:
IOException
-
createLink
protected abstract void createLink(int id, String existingPath, String linkPath, boolean symLink) throws IOException - Throws:
IOException
-
doOpenSSHHardLink
- Throws:
IOException
-
doOpenSSHLimits
- Throws:
IOException
-
getOpenSSHLimitsExtensionInfo
protected OpenSSHLimitsExtensionInfo getOpenSSHLimitsExtensionInfo(int id, ChannelSession channel) throws IOException - Throws:
IOException
-
doOpenSSHHardLink
- Throws:
IOException
-
doSpaceAvailable
- Throws:
IOException
-
doSpaceAvailable
- Throws:
IOException
-
doTextSeek
- Throws:
IOException
-
doTextSeek
- Throws:
IOException
-
doOpenSSHFsync
- Throws:
IOException
-
doOpenSSHFsync
- Throws:
IOException
-
doCheckFileHash
- Throws:
IOException
-
doCheckFileHash
protected void doCheckFileHash(int id, Path file, NamedFactory<? extends Digest> factory, long startOffset, long length, int blockSize, Buffer buffer) throws Exception - Throws:
Exception
-
doMD5Hash
- Throws:
IOException
-
doMD5Hash
protected abstract byte[] doMD5Hash(int id, String targetType, String target, long startOffset, long length, byte[] quickCheckHash) throws Exception - Throws:
Exception
-
doMD5Hash
protected byte[] doMD5Hash(int id, Path path, long startOffset, long length, byte[] quickCheckHash) throws Exception - Throws:
Exception
-
doCheckFileHash
protected abstract void doCheckFileHash(int id, String targetType, String target, Collection<String> algos, long startOffset, long length, int blockSize, Buffer buffer) throws Exception - Throws:
Exception
-
doReadLink
- Throws:
IOException
-
doReadLink
protected AbstractMap.SimpleImmutableEntry<Path,String> doReadLink(int id, String path) throws IOException - Parameters:
id- Request identifierpath- Referenced path- Returns:
- A "pair" containing the local link
Pathand its referenced symbolic link - Throws:
IOException- If failed to resolve the requested data
-
doRename
- Throws:
IOException
-
doRename
- Throws:
IOException
-
doRename
protected void doRename(int id, String oldPath, String newPath, Collection<CopyOption> opts) throws IOException - Throws:
IOException
-
doPosixRename
- Throws:
IOException
-
doCopyData
- Throws:
IOException
-
doCopyData
protected abstract void doCopyData(int id, String readHandle, long readOffset, long readLength, String writeHandle, long writeOffset) throws IOException - Throws:
IOException
-
doCopyFile
- Throws:
IOException
-
doCopyFile
protected void doCopyFile(int id, String srcFile, String dstFile, boolean overwriteDestination) throws IOException - Throws:
IOException
-
doCopyFile
protected void doCopyFile(int id, String srcFile, String dstFile, Collection<CopyOption> opts) throws IOException - Throws:
IOException
-
doBlock
- Throws:
IOException
-
doBlock
protected abstract void doBlock(int id, String handle, long offset, long length, int mask) throws IOException - Throws:
IOException
-
doUnblock
- Throws:
IOException
-
doUnblock
protected abstract void doUnblock(int id, String handle, long offset, long length) throws IOException - Throws:
IOException
-
doStat
- Throws:
IOException
-
doStat
- Throws:
IOException
-
doRealPath
- Throws:
IOException
-
doRealPathV6
protected AbstractMap.SimpleImmutableEntry<Path,Boolean> doRealPathV6(int id, String path, Collection<String> extraPaths, Path p, LinkOption... options) throws IOException - Throws:
IOException
-
doRealPathV345
protected AbstractMap.SimpleImmutableEntry<Path,Boolean> doRealPathV345(int id, String path, Path p, LinkOption... options) throws IOException - Throws:
IOException
-
validateRealPath
protected AbstractMap.SimpleImmutableEntry<Path,Boolean> validateRealPath(int id, String path, Path f, LinkOption... options) throws IOException - Parameters:
id- The request identifierpath- The original pathf- The resolvePathoptions- TheLinkOptions to use to verify file existence and access- Returns:
- A
AbstractMap.SimpleImmutableEntrywhose key is the absolute normalizedPathand value is aBooleanindicating its status - Throws:
IOException- If failed to validate the file- See Also:
-
doRemoveDirectory
- Throws:
IOException
-
doRemoveDirectory
- Throws:
IOException
-
doRemove
Called when need to delete a file / directory - also informs theSftpEventListener- Parameters:
id- Deletion request IDp-Pathto deleteisDirectory- Whether the requested path represents a directory or a regular file- Throws:
IOException- If failed to delete
-
doMakeDirectory
- Throws:
IOException
-
doMakeDirectory
- Throws:
IOException
-
doRemove
- Throws:
IOException
-
doRemoveFile
- Throws:
IOException
-
signalRemovalPreConditionFailure
protected <E extends IOException> E signalRemovalPreConditionFailure(int id, String pathValue, Path path, E thrown, boolean isRemoveDirectory) throws IOException - Throws:
IOException
-
doExtended
- Throws:
IOException
-
executeExtendedCommand
- Parameters:
buffer- The commandBufferid- The request idextension- The extension name- Throws:
IOException- If failed to execute the extension
-
doUnsupportedExtension
- Throws:
IOException
-
appendExtensions
-
appendAclSupportedExtension
-
resolveAclSupportedCapabilities
-
appendOpenSSHExtensions
protected List<AbstractOpenSSHExtensionParser.OpenSSHExtension> appendOpenSSHExtensions(Buffer buffer, ServerSession session) -
resolveOpenSSHExtensions
protected List<AbstractOpenSSHExtensionParser.OpenSSHExtension> resolveOpenSSHExtensions(ServerSession session) -
getSupportedClientExtensions
-
appendVersionsExtension
Appends the "versions" extension to the buffer. Note: if overriding this method make sure you either do not append anything or use the correct extension name- Parameters:
buffer- TheBufferto append tovalue- The recommended value - ignored ifnull/emptysession- TheServerSessionfor which this extension is added- Returns:
- The apended value
- See Also:
-
appendNewlineExtension
Appends the "newline" extension to the buffer. Note: if overriding this method make sure you either do not append anything or use the correct extension name- Parameters:
buffer- TheBufferto append tosession- TheServerSessionfor which this extension is added- Returns:
- The appended value
- See Also:
-
resolveNewlineValue
-
appendVendorIdExtension
protected Map<String,?> appendVendorIdExtension(Buffer buffer, Map<String, ?> versionProperties, ServerSession session) Appends the "vendor-id" extension to the buffer. Note: if overriding this method make sure you either do not append anything or use the correct extension name- Parameters:
buffer- TheBufferto append toversionProperties- The currently available version properties - ignored ifnull/empty. The code expects the following values:groupId- as the vendor nameartifactId- as the product nameversion- as the product version
session- TheServerSessionfor which these properties are added- Returns:
- The version properties
- See Also:
-
appendSupportedExtension
Appends the "supported" extension to the buffer. Note: if overriding this method make sure you either do not append anything or use the correct extension name- Parameters:
buffer- TheBufferto append toextras- The extra extensions that are available and can be reported - may benull/empty
-
appendSupported2Extension
Appends the "supported2" extension to the buffer. Note: if overriding this method make sure you either do not append anything or use the correct extension name- Parameters:
buffer- TheBufferto append toextras- The extra extensions that are available and can be reported - may benull/empty- See Also:
-
sendHandle
- Throws:
IOException
-
sendAttrs
- Throws:
IOException
-
sendLink
- Throws:
IOException
-
sendPath
- Throws:
IOException
-
doReadDir
protected int doReadDir(int id, String handle, DirectoryHandle dir, Buffer buffer, int maxSize, boolean followLinks) throws IOException - Parameters:
id- Request idhandle- The (opaque) handle assigned to this directorydir- TheDirectoryHandlebuffer- TheBufferto write the resultsmaxSize- Max. buffer sizefollowLinks- Whether to follow symbolic links when querying the directory contents- Returns:
- Number of written entries
- Throws:
IOException- If failed to generate an entry
-
writeDirEntry
protected void writeDirEntry(ServerSession session, int id, Buffer buffer, int index, Path f, String shortName, SftpClient.Attributes attributes) throws IOException - Throws:
IOException
-
writeDirEntry
protected void writeDirEntry(int id, DirectoryHandle dir, Map<String, Path> entries, Buffer buffer, int index, Path f, String shortName, LinkOption... options) throws IOException- Parameters:
id- Request iddir- TheDirectoryHandleentries- An in / outMapfor updating the written entry - key = short name, value = entryPathbuffer- TheBufferto write the resultsindex- Zero-based index of the entry to be writtenf- The entryPathshortName- The entry short nameoptions- TheLinkOptions to use for querying the entry-s attributes- Throws:
IOException- If failed to generate the entry data
-
getLongName
- Throws:
IOException
-
getLongName
protected String getLongName(Path f, String shortName, boolean sendAttrs, LinkOption... options) throws IOException - Throws:
IOException
-
getLongName
- Throws:
IOException
-
getLongName
protected String getLongName(Path f, String shortName, SftpClient.Attributes attributes) throws IOException - Throws:
IOException
-
getShortName
- Throws:
IOException
-
resolveFileAttributes
protected NavigableMap<String,Object> resolveFileAttributes(Path path, int flags, boolean neverFollowSymLinks, LinkOption... options) throws IOException - Throws:
IOException
-
checkSymlinkState
A utility function to validate that the directories leading up to a file are not symlinks- Parameters:
path- the file to check for symlink presenceneverFollowSymLinks- whether to never follow symlinks in the parent pathsoptions- whether the file itself can be a symlink- Returns:
- whether there are symlinks in the path to this file, or null if unknown
-
validateParentExistWithNoSymlinksIfNeverFollowSymlinks
-
writeAttrs
-
getAttributes
protected NavigableMap<String,Object> getAttributes(Path file, LinkOption... options) throws IOException - Throws:
IOException
-
handleUnknownStatusFileAttributes
protected NavigableMap<String,Object> handleUnknownStatusFileAttributes(Path file, int flags, LinkOption... options) throws IOException - Throws:
IOException
-
getAttributes
protected NavigableMap<String,Object> getAttributes(Path path, int flags, LinkOption... options) throws IOException - Parameters:
path- ThePathlocation for the required attributesflags- A mask of the original required attributes - ignored by the default implementationoptions- TheLinkOptions to use in order to access the file if necessary- Returns:
- A
Mapof the retrieved attributes - Throws:
IOException- If failed to access the file- See Also:
-
resolveReportedFileAttributes
protected NavigableMap<String,Object> resolveReportedFileAttributes(Path file, int flags, LinkOption... options) throws IOException - Throws:
IOException
-
resolveMissingFileAttributes
protected NavigableMap<String,Object> resolveMissingFileAttributes(Path file, int flags, Map<String, Object> current, LinkOption... options) throws IOExceptionCalled bygetAttributes(Path, int, LinkOption...)in order to complete any attributes that could not be retrieved via the supported file system views. These attributes are deemed important so an extra effort is made to provide a value for them- Parameters:
file- ThePathlocation for the required attributesflags- A mask of the original required attributes - ignored by the default implementationcurrent- TheMapof attributes already retrieved - may benull/empty and/or unmodifiableoptions- TheLinkOptions to use in order to access the file if necessary- Returns:
- A
Mapof the extra attributes whose values need to be updated in the original map. Note: it is allowed to specify values which override existing ones - the default implementation does not override values that have a non-nullvalue - Throws:
IOException- If failed to access the attributes - in which case an error is returned to the SFTP client- See Also:
-
resolveMissingFileAttributeValue
protected Object resolveMissingFileAttributeValue(Path file, String name, Object value, FileInfoExtractor<?> x, LinkOption... options) throws IOException - Throws:
IOException
-
readFileAttributes
protected NavigableMap<String,Object> readFileAttributes(Path file, String view, LinkOption... options) throws IOException - Throws:
IOException
-
handleReadFileAttributesException
protected NavigableMap<String,Object> handleReadFileAttributesException(Path file, String view, LinkOption[] options, IOException e) throws IOException - Throws:
IOException
-
doSetAttributes
protected void doSetAttributes(int cmd, String extension, Path file, Map<String, ?> attributes, boolean followLinks) throws IOException- Throws:
IOException
-
getPathResolutionLinkOption
protected LinkOption[] getPathResolutionLinkOption(int cmd, String extension, Path path) throws IOException - Throws:
IOException
-
resolvePathResolutionFollowLinks
protected boolean resolvePathResolutionFollowLinks(int cmd, String extension, Path path) throws IOException - Throws:
IOException
-
setFileAttributes
protected void setFileAttributes(Path file, Map<String, ?> attributes, LinkOption... options) throws IOException- Throws:
IOException
-
handleSetFileAttributeFailure
protected void handleSetFileAttributeFailure(Path file, String view, String attribute, Object value, Collection<String> unsupported, Exception e) throws IOException - Throws:
IOException
-
setFileAttribute
protected void setFileAttribute(Path file, String view, String attribute, Object value, LinkOption... options) throws IOException - Throws:
IOException
-
setFileTime
protected void setFileTime(Path file, String view, String attribute, FileTime value, LinkOption... options) throws IOException - Throws:
IOException
-
setFileRawViewAttribute
protected void setFileRawViewAttribute(Path file, String view, String attribute, Object value, LinkOption... options) throws IOException - Throws:
IOException
-
setFileOwnership
protected void setFileOwnership(Path file, String attribute, Principal value, LinkOption... options) throws IOException - Throws:
IOException
-
setFileExtensions
protected void setFileExtensions(Path file, Map<String, byte[]> extensions, LinkOption... options) throws IOException- Throws:
IOException
-
setFilePermissions
protected void setFilePermissions(Path file, Set<PosixFilePermission> perms, LinkOption... options) throws IOException - Throws:
IOException
-
setFileAccessControl
protected void setFileAccessControl(Path file, List<AclEntry> acl, LinkOption... options) throws IOException - Throws:
IOException
-
handleUnsupportedAttributes
-
toGroup
- Throws:
IOException
-
toUser
- Throws:
IOException
-
handleUserPrincipalLookupServiceException
protected void handleUserPrincipalLookupServiceException(Class<? extends Principal> principalType, String name, IOException e) throws IOException - Throws:
IOException
-
readAttrs
- Throws:
IOException
-
validateHandle
protected <H extends Handle> H validateHandle(String handle, Handle h, Class<H> type) throws IOException Makes sure that the local handle is not null and of the specified type- Type Parameters:
H- The generic handle type- Parameters:
handle- The original handle idh- The resolvedHandleinstancetype- The expected handle type- Returns:
- The cast type
- Throws:
IOException- If a generic exception occurredFileNotFoundException- If the handle instance isnullInvalidHandleException- If the handle instance is not of the expected type
-
sendStatus
protected void sendStatus(Buffer buffer, int id, Throwable e, int cmd, Object... args) throws IOException Invoked when an exception was thrown due to the execution of some SFTP command- Parameters:
buffer- ABufferto be used to build the status replyid- Command identifiere- Thrown exceptioncmd- The command that was attemptedargs- The relevant command arguments - Note: provided only for logging purposes and subject to type and/or order change at any version- Throws:
IOException- If failed to build and send the status buffer
-
sendStatus
- Throws:
IOException
-
sendStatus
protected void sendStatus(Buffer buffer, int id, int substatus, String msg, String lang) throws IOException - Throws:
IOException
-
prepareReply
-
send
- Throws:
IOException
-
resolveNormalizedLocation
protected Path resolveNormalizedLocation(String remotePath) throws IOException, InvalidPathException - Throws:
IOExceptionInvalidPathException
-
normalize
-
resolveFile
- Parameters:
remotePath- The remote path - separated by '/'- Returns:
- The local
Path - Throws:
IOException- If failed to resolve the local pathInvalidPathException- If bad local path specification
-