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 org.apache.sshd.common.util.logging.AbstractLoggingBean
implements SftpSubsystemProxy
- Author:
- Apache MINA SSHD Project
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final List<AbstractOpenSSHExtensionParser.OpenSSHExtension> static final NavigableMap<String, OptionalFeature> The default reported supported client extensions (case insensitive)Fields 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, org.apache.sshd.common.util.io.FileInfoExtractor<?> x, LinkOption... options) booleanaddSftpEventListener(SftpEventListener listener) Register a listener instanceprotected intappendAclSupportedExtension(org.apache.sshd.common.util.buffer.Buffer buffer, ServerSession session) protected voidappendExtensions(org.apache.sshd.common.util.buffer.Buffer buffer, String supportedVersions) protected StringappendNewlineExtension(org.apache.sshd.common.util.buffer.Buffer buffer, ServerSession session) Appends the "newline" extension to the buffer.appendOpenSSHExtensions(org.apache.sshd.common.util.buffer.Buffer buffer, ServerSession session) protected voidappendSupported2Extension(org.apache.sshd.common.util.buffer.Buffer buffer, Collection<String> extras) Appends the "supported2" extension to the buffer.protected voidappendSupportedExtension(org.apache.sshd.common.util.buffer.Buffer buffer, Collection<String> extras) Appends the "supported" extension to the buffer.appendVendorIdExtension(org.apache.sshd.common.util.buffer.Buffer buffer, Map<String, ?> versionProperties, ServerSession session) Appends the "vendor-id" extension to the buffer.protected StringappendVersionsExtension(org.apache.sshd.common.util.buffer.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(org.apache.sshd.common.util.buffer.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 voiddoBlock(org.apache.sshd.common.util.buffer.Buffer buffer, int id) protected abstract voiddoCheckFileHash(int id, String targetType, String target, Collection<String> algos, long startOffset, long length, int blockSize, org.apache.sshd.common.util.buffer.Buffer buffer) protected voiddoCheckFileHash(int id, Path file, NamedFactory<? extends org.apache.sshd.common.digest.Digest> factory, long startOffset, long length, int blockSize, org.apache.sshd.common.util.buffer.Buffer buffer) protected voiddoCheckFileHash(org.apache.sshd.common.util.buffer.Buffer buffer, int id, String targetType) protected abstract voidprotected voiddoClose(org.apache.sshd.common.util.buffer.Buffer buffer, int id) protected abstract voiddoCopyData(int id, String readHandle, long readOffset, long readLength, String writeHandle, long writeOffset) protected voiddoCopyData(org.apache.sshd.common.util.buffer.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(org.apache.sshd.common.util.buffer.Buffer buffer, int id) protected voiddoExtended(org.apache.sshd.common.util.buffer.Buffer buffer, int id) protected abstract voiddoFSetStat(int id, String handle, Map<String, ?> attrs) protected voiddoFSetStat(org.apache.sshd.common.util.buffer.Buffer buffer, int id) protected voiddoFStat(org.apache.sshd.common.util.buffer.Buffer buffer, int id) protected abstract voiddoInit(org.apache.sshd.common.util.buffer.Buffer buffer, int id) protected voidprotected voiddoLink(org.apache.sshd.common.util.buffer.Buffer buffer, int id) protected voiddoLStat(org.apache.sshd.common.util.buffer.Buffer buffer, int id) protected voiddoMakeDirectory(int id, String path, Map<String, ?> attrs) protected voiddoMakeDirectory(org.apache.sshd.common.util.buffer.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 voiddoOpen(org.apache.sshd.common.util.buffer.Buffer buffer, int id) protected abstract StringdoOpenDir(int id, String path, Path p, LinkOption... options) protected voiddoOpenDir(org.apache.sshd.common.util.buffer.Buffer buffer, int id) protected abstract voiddoOpenSSHFsync(int id, String handle) protected voiddoOpenSSHFsync(org.apache.sshd.common.util.buffer.Buffer buffer, int id) protected voiddoOpenSSHHardLink(int id, String srcFile, String dstFile) protected voiddoOpenSSHHardLink(org.apache.sshd.common.util.buffer.Buffer buffer, int id) protected voiddoOpenSSHLimits(org.apache.sshd.common.util.buffer.Buffer buffer, int id) protected voiddoPosixRename(org.apache.sshd.common.util.buffer.Buffer buffer, int id) protected voiddoProcess(org.apache.sshd.common.util.buffer.Buffer buffer, int length, int type, int id) protected abstract intdoRead(int id, String handle, long offset, int length, byte[] data, int doff, AtomicReference<Boolean> eof) protected voiddoRead(org.apache.sshd.common.util.buffer.Buffer buffer, int id) protected intdoReadDir(int id, String handle, DirectoryHandle dir, org.apache.sshd.common.util.buffer.Buffer buffer, int maxSize, boolean followLinks) protected abstract voiddoReadDir(org.apache.sshd.common.util.buffer.Buffer buffer, int id) protected AbstractMap.SimpleImmutableEntry<Path, String> doReadLink(int id, String path) protected voiddoReadLink(org.apache.sshd.common.util.buffer.Buffer buffer, int id) protected voiddoRealPath(org.apache.sshd.common.util.buffer.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 voiddoRemove(org.apache.sshd.common.util.buffer.Buffer buffer, int id) protected voiddoRemoveDirectory(int id, String path) protected voiddoRemoveDirectory(org.apache.sshd.common.util.buffer.Buffer buffer, int id) protected voiddoRemoveFile(int id, String path) protected voidprotected voiddoRename(int id, String oldPath, String newPath, Collection<CopyOption> opts) protected voiddoRename(org.apache.sshd.common.util.buffer.Buffer buffer, int id) protected voiddoSetAttributes(int cmd, String extension, Path file, Map<String, ?> attributes, boolean followLinks) protected voidprotected voiddoSetStat(org.apache.sshd.common.util.buffer.Buffer buffer, int id, String extension, int cmd, Boolean followLinks) protected SpaceAvailableExtensionInfodoSpaceAvailable(int id, String path) protected voiddoSpaceAvailable(org.apache.sshd.common.util.buffer.Buffer buffer, int id) protected voiddoStat(org.apache.sshd.common.util.buffer.Buffer buffer, int id) protected voidprotected voiddoSymLink(org.apache.sshd.common.util.buffer.Buffer buffer, int id) protected abstract voiddoTextSeek(int id, String handle, long line) protected voiddoTextSeek(org.apache.sshd.common.util.buffer.Buffer buffer, int id) protected abstract voidprotected voiddoUnblock(org.apache.sshd.common.util.buffer.Buffer buffer, int id) protected voiddoUnsupported(org.apache.sshd.common.util.buffer.Buffer buffer, int length, int type, int id) protected voiddoUnsupportedExtension(org.apache.sshd.common.util.buffer.Buffer buffer, int id, String extension) protected voiddoVersionSelect(org.apache.sshd.common.util.buffer.Buffer buffer, int id) protected abstract voiddoVersionSelect(org.apache.sshd.common.util.buffer.Buffer buffer, int id, String proposed) protected abstract voidprotected voiddoWrite(org.apache.sshd.common.util.buffer.Buffer buffer, int id) protected voidexecuteExtendedCommand(org.apache.sshd.common.util.buffer.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 org.apache.sshd.common.util.buffer.BufferprepareReply(org.apache.sshd.common.util.buffer.Buffer buffer) protected voidprocess(org.apache.sshd.common.util.buffer.Buffer buffer) Process an SFTP command.readAttrs(org.apache.sshd.common.util.buffer.Buffer buffer) 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, org.apache.sshd.common.util.io.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 voidsend(org.apache.sshd.common.util.buffer.Buffer buffer) protected voidprotected voidsendHandle(org.apache.sshd.common.util.buffer.Buffer buffer, int id, String handle) protected voidprotected voidprotected voidsendStatus(org.apache.sshd.common.util.buffer.Buffer buffer, int id, int substatus, String msg) protected voidsendStatus(org.apache.sshd.common.util.buffer.Buffer buffer, int id, int substatus, String msg, String lang) protected voidsendStatus(org.apache.sshd.common.util.buffer.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(org.apache.sshd.common.util.buffer.Buffer buffer, int id, String proposal) protected AbstractMap.SimpleImmutableEntry<Path, Boolean> validateRealPath(int id, String path, Path f, LinkOption... options) protected voidwriteAttrs(org.apache.sshd.common.util.buffer.Buffer buffer, Map<String, ?> attributes) protected voidwriteDirEntry(int id, DirectoryHandle dir, Map<String, Path> entries, org.apache.sshd.common.util.buffer.Buffer buffer, int index, Path f, String shortName, LinkOption... options) protected voidwriteDirEntry(ServerSession session, int id, org.apache.sshd.common.util.buffer.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
-
-
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(org.apache.sshd.common.util.buffer.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(org.apache.sshd.common.util.buffer.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
protected void doProcess(org.apache.sshd.common.util.buffer.Buffer buffer, int length, int type, int id) throws IOException - Throws:
IOException
-
doUnsupported
protected void doUnsupported(org.apache.sshd.common.util.buffer.Buffer buffer, int length, int type, int id) throws IOException - Throws:
IOException
-
doInit
protected abstract void doInit(org.apache.sshd.common.util.buffer.Buffer buffer, int id) throws IOException - Throws:
IOException
-
doVersionSelect
protected void doVersionSelect(org.apache.sshd.common.util.buffer.Buffer buffer, int id) throws IOException - Throws:
IOException
-
doVersionSelect
protected abstract void doVersionSelect(org.apache.sshd.common.util.buffer.Buffer buffer, int id, String proposed) throws IOException - 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(org.apache.sshd.common.util.buffer.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
protected void doFSetStat(org.apache.sshd.common.util.buffer.Buffer buffer, int id) throws IOException - Throws:
IOException
-
doFSetStat
- Throws:
IOException
-
doOpenDir
protected void doOpenDir(org.apache.sshd.common.util.buffer.Buffer buffer, int id) throws IOException - Throws:
IOException
-
doOpenDir
protected abstract String doOpenDir(int id, String path, Path p, LinkOption... options) throws IOException - Throws:
IOException
-
doReadDir
protected abstract void doReadDir(org.apache.sshd.common.util.buffer.Buffer buffer, int id) throws IOException - Throws:
IOException
-
doLink
- Throws:
IOException
-
doLink
protected void doLink(int id, String targetPath, String linkPath, boolean symLink) throws IOException - Throws:
IOException
-
doSymLink
protected void doSymLink(org.apache.sshd.common.util.buffer.Buffer buffer, int id) throws IOException - Throws:
IOException
-
doSymLink
- Throws:
IOException
-
createLink
protected abstract void createLink(int id, String existingPath, String linkPath, boolean symLink) throws IOException - Throws:
IOException
-
doOpenSSHHardLink
protected void doOpenSSHHardLink(org.apache.sshd.common.util.buffer.Buffer buffer, int id) throws IOException - Throws:
IOException
-
doOpenSSHLimits
protected void doOpenSSHLimits(org.apache.sshd.common.util.buffer.Buffer buffer, int id) throws IOException - Throws:
IOException
-
getOpenSSHLimitsExtensionInfo
protected OpenSSHLimitsExtensionInfo getOpenSSHLimitsExtensionInfo(int id, ChannelSession channel) throws IOException - Throws:
IOException
-
doOpenSSHHardLink
- Throws:
IOException
-
doSpaceAvailable
protected void doSpaceAvailable(org.apache.sshd.common.util.buffer.Buffer buffer, int id) throws IOException - Throws:
IOException
-
doSpaceAvailable
- Throws:
IOException
-
doTextSeek
protected void doTextSeek(org.apache.sshd.common.util.buffer.Buffer buffer, int id) throws IOException - Throws:
IOException
-
doTextSeek
- Throws:
IOException
-
doOpenSSHFsync
protected void doOpenSSHFsync(org.apache.sshd.common.util.buffer.Buffer buffer, int id) throws IOException - Throws:
IOException
-
doOpenSSHFsync
- Throws:
IOException
-
doCheckFileHash
protected void doCheckFileHash(org.apache.sshd.common.util.buffer.Buffer buffer, int id, String targetType) throws IOException - Throws:
IOException
-
doCheckFileHash
protected void doCheckFileHash(int id, Path file, NamedFactory<? extends org.apache.sshd.common.digest.Digest> factory, long startOffset, long length, int blockSize, org.apache.sshd.common.util.buffer.Buffer buffer) throws Exception - Throws:
Exception
-
doMD5Hash
protected void doMD5Hash(org.apache.sshd.common.util.buffer.Buffer buffer, int id, String targetType) throws IOException - 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, org.apache.sshd.common.util.buffer.Buffer buffer) throws Exception - Throws:
Exception
-
doReadLink
protected void doReadLink(org.apache.sshd.common.util.buffer.Buffer buffer, int id) throws IOException - 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
protected void doRename(org.apache.sshd.common.util.buffer.Buffer buffer, int id) throws IOException - Throws:
IOException
-
doRename
- Throws:
IOException
-
doRename
protected void doRename(int id, String oldPath, String newPath, Collection<CopyOption> opts) throws IOException - Throws:
IOException
-
doPosixRename
protected void doPosixRename(org.apache.sshd.common.util.buffer.Buffer buffer, int id) throws IOException - Throws:
IOException
-
doCopyData
protected void doCopyData(org.apache.sshd.common.util.buffer.Buffer buffer, int id) throws IOException - Throws:
IOException
-
doCopyData
protected abstract void doCopyData(int id, String readHandle, long readOffset, long readLength, String writeHandle, long writeOffset) throws IOException - Throws:
IOException
-
doCopyFile
protected void doCopyFile(org.apache.sshd.common.util.buffer.Buffer buffer, int id) throws IOException - 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
protected void doUnblock(org.apache.sshd.common.util.buffer.Buffer buffer, int id) throws IOException - 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
protected void doRealPath(org.apache.sshd.common.util.buffer.Buffer buffer, int id) throws IOException - 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
protected void doRemoveDirectory(org.apache.sshd.common.util.buffer.Buffer buffer, int id) throws IOException - 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
protected void doMakeDirectory(org.apache.sshd.common.util.buffer.Buffer buffer, int id) throws IOException - Throws:
IOException
-
doMakeDirectory
- Throws:
IOException
-
doRemove
protected void doRemove(org.apache.sshd.common.util.buffer.Buffer buffer, int id) throws IOException - 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
protected void doExtended(org.apache.sshd.common.util.buffer.Buffer buffer, int id) throws IOException - Throws:
IOException
-
executeExtendedCommand
protected void executeExtendedCommand(org.apache.sshd.common.util.buffer.Buffer buffer, int id, String extension) throws IOException - Parameters:
buffer- The commandBufferid- The request idextension- The extension name- Throws:
IOException- If failed to execute the extension
-
doUnsupportedExtension
protected void doUnsupportedExtension(org.apache.sshd.common.util.buffer.Buffer buffer, int id, String extension) throws IOException - Throws:
IOException
-
appendExtensions
protected void appendExtensions(org.apache.sshd.common.util.buffer.Buffer buffer, String supportedVersions) -
appendAclSupportedExtension
protected int appendAclSupportedExtension(org.apache.sshd.common.util.buffer.Buffer buffer, ServerSession session) -
resolveAclSupportedCapabilities
-
appendOpenSSHExtensions
protected List<AbstractOpenSSHExtensionParser.OpenSSHExtension> appendOpenSSHExtensions(org.apache.sshd.common.util.buffer.Buffer buffer, ServerSession session) -
resolveOpenSSHExtensions
protected List<AbstractOpenSSHExtensionParser.OpenSSHExtension> resolveOpenSSHExtensions(ServerSession session) -
getSupportedClientExtensions
-
appendVersionsExtension
protected String appendVersionsExtension(org.apache.sshd.common.util.buffer.Buffer buffer, String value, ServerSession session) 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
protected String appendNewlineExtension(org.apache.sshd.common.util.buffer.Buffer buffer, ServerSession session) 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(org.apache.sshd.common.util.buffer.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
protected void appendSupportedExtension(org.apache.sshd.common.util.buffer.Buffer buffer, Collection<String> extras) 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
protected void appendSupported2Extension(org.apache.sshd.common.util.buffer.Buffer buffer, Collection<String> extras) 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
protected void sendHandle(org.apache.sshd.common.util.buffer.Buffer buffer, int id, String handle) throws IOException - Throws:
IOException
-
sendAttrs
protected void sendAttrs(org.apache.sshd.common.util.buffer.Buffer buffer, int id, Map<String, ?> attributes) throws IOException- Throws:
IOException
-
sendLink
protected void sendLink(org.apache.sshd.common.util.buffer.Buffer buffer, int id, Path file, String link) throws IOException - Throws:
IOException
-
sendPath
protected void sendPath(org.apache.sshd.common.util.buffer.Buffer buffer, int id, Path f, Map<String, ?> attrs) throws IOException- Throws:
IOException
-
doReadDir
protected int doReadDir(int id, String handle, DirectoryHandle dir, org.apache.sshd.common.util.buffer.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, org.apache.sshd.common.util.buffer.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, org.apache.sshd.common.util.buffer.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, org.apache.sshd.common.util.io.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
protected Map<String,Object> readAttrs(org.apache.sshd.common.util.buffer.Buffer buffer) throws IOException - 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(org.apache.sshd.common.util.buffer.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
protected void sendStatus(org.apache.sshd.common.util.buffer.Buffer buffer, int id, int substatus, String msg) throws IOException - Throws:
IOException
-
sendStatus
protected void sendStatus(org.apache.sshd.common.util.buffer.Buffer buffer, int id, int substatus, String msg, String lang) throws IOException - Throws:
IOException
-
prepareReply
protected abstract org.apache.sshd.common.util.buffer.Buffer prepareReply(org.apache.sshd.common.util.buffer.Buffer buffer) -
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
-