Class AbstractSftpSubsystemHelper

java.lang.Object
org.apache.sshd.common.util.logging.AbstractLoggingBean
org.apache.sshd.sftp.server.AbstractSftpSubsystemHelper
All Implemented Interfaces:
org.apache.sshd.common.session.SessionContextHolder, org.apache.sshd.common.session.SessionHolder<org.apache.sshd.server.session.ServerSession>, org.apache.sshd.server.channel.ServerChannelSessionHolder, org.apache.sshd.server.session.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 Details

    • DEFAULT_SUPPORTED_CLIENT_EXTENSIONS

      public static final NavigableMap<String,org.apache.sshd.common.OptionalFeature> 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

      public static final List<String> DEFAULT_OPEN_SSH_EXTENSIONS_NAMES
    • DEFAULT_ACL_SUPPORTED_MASK

      public static final Set<Integer> DEFAULT_ACL_SUPPORTED_MASK
  • Constructor Details

    • AbstractSftpSubsystemHelper

      protected AbstractSftpSubsystemHelper(org.apache.sshd.server.channel.ChannelSession channelSession, SftpSubsystemConfigurator configurator)
  • Method Details

    • getServerChannelSession

      public org.apache.sshd.server.channel.ChannelSession getServerChannelSession()
      Specified by:
      getServerChannelSession in interface org.apache.sshd.server.channel.ServerChannelSessionHolder
    • getUnsupportedAttributePolicy

      public UnsupportedAttributePolicy getUnsupportedAttributePolicy()
      Specified by:
      getUnsupportedAttributePolicy in interface SftpUnsupportedAttributePolicyProvider
      Returns:
      The UnsupportedAttributePolicy to use if failed to access some local file attributes
    • getFileSystemAccessor

      public SftpFileSystemAccessor getFileSystemAccessor()
      Specified by:
      getFileSystemAccessor in interface SftpFileSystemAccessorProvider
      Returns:
      The SftpFileSystemAccessor to use for accessing files and directories
    • getSftpEventListenerProxy

      public SftpEventListener getSftpEventListenerProxy()
      Specified by:
      getSftpEventListenerProxy in interface SftpEventListenerManager
      Returns:
      An instance representing all the currently registered listeners. Any method invocation is replicated to the actually registered listeners
    • addSftpEventListener

      public boolean addSftpEventListener(SftpEventListener listener)
      Description copied from interface: SftpEventListenerManager
      Register a listener instance
      Specified by:
      addSftpEventListener in interface SftpEventListenerManager
      Parameters:
      listener - The SftpEventListener instance to add - never null
      Returns:
      true if listener is a previously un-registered one
    • removeSftpEventListener

      public boolean removeSftpEventListener(SftpEventListener listener)
      Description copied from interface: SftpEventListenerManager
      Remove a listener instance
      Specified by:
      removeSftpEventListener in interface SftpEventListenerManager
      Parameters:
      listener - The SftpEventListener instance to remove - never null
      Returns:
      true if listener is a (removed) registered one
    • getErrorStatusDataHandler

      public SftpErrorStatusDataHandler getErrorStatusDataHandler()
      Specified by:
      getErrorStatusDataHandler in interface SftpErrorStatusDataHandlerProvider
      Returns:
      The (never null) SftpErrorStatusDataHandler to 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 - The Buffer holding the request
      id - The request id
      proposal - The proposed value
      Returns:
      A Boolean indicating whether to accept/reject the proposal. If null then 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 the SftpModuleProperties.SFTP_VERSION property, then it is used to validate the proposed value
      Parameters:
      buffer - The Buffer containing the request
      id - The SSH message ID to be used to send the failure message if required
      proposed - The proposed version value
      failureOpcode - The failure opcode to send if validation fails
      Returns:
      A "pair" whose key is the negotiated version and value a String of comma separated values representing all the supported versions. null if validation failed and an appropriate status message was sent
      Throws:
      IOException - If failed to send the failure status message
    • process

      protected void process(org.apache.sshd.common.util.buffer.Buffer buffer) throws IOException
      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

      protected void doOpen(org.apache.sshd.common.util.buffer.Buffer buffer, int id) throws IOException
      Throws:
      IOException
    • doOpen

      protected abstract String doOpen(int id, String path, int pflags, int access, Map<String,Object> attrs) throws IOException
      Parameters:
      id - Request id
      path - Path
      pflags - Open mode flags - see SSH_FXF_XXX flags
      access - Access mode flags - see ACE4_XXX flags
      attrs - 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

      protected void doClose(org.apache.sshd.common.util.buffer.Buffer buffer, int id) throws IOException
      Throws:
      IOException
    • doClose

      protected abstract void doClose(int id, String handle) throws IOException
      Throws:
      IOException
    • doRead

      protected void doRead(org.apache.sshd.common.util.buffer.Buffer buffer, int id) throws IOException
      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

      protected void doWrite(org.apache.sshd.common.util.buffer.Buffer buffer, int id) throws IOException
      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

      protected void doLStat(org.apache.sshd.common.util.buffer.Buffer buffer, int id) throws IOException
      Throws:
      IOException
    • doLStat

      protected Map<String,Object> doLStat(int id, String path, int flags) throws IOException
      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

      protected void doFStat(org.apache.sshd.common.util.buffer.Buffer buffer, int id) throws IOException
      Throws:
      IOException
    • doFStat

      protected abstract Map<String,Object> doFStat(int id, String handle, int flags) throws IOException
      Throws:
      IOException
    • doFSetStat

      protected void doFSetStat(org.apache.sshd.common.util.buffer.Buffer buffer, int id) throws IOException
      Throws:
      IOException
    • doFSetStat

      protected abstract void doFSetStat(int id, String handle, Map<String,?> attrs) throws IOException
      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

      protected void doLink(org.apache.sshd.common.util.buffer.Buffer buffer, int id) throws IOException
      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

      protected void doSymLink(int id, String targetPath, String linkPath) throws IOException
      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, org.apache.sshd.server.channel.ChannelSession channel) throws IOException
      Throws:
      IOException
    • doOpenSSHHardLink

      protected void doOpenSSHHardLink(int id, String srcFile, String dstFile) throws IOException
      Throws:
      IOException
    • doSpaceAvailable

      protected void doSpaceAvailable(org.apache.sshd.common.util.buffer.Buffer buffer, int id) throws IOException
      Throws:
      IOException
    • doSpaceAvailable

      protected SpaceAvailableExtensionInfo doSpaceAvailable(int id, String path) throws IOException
      Throws:
      IOException
    • doTextSeek

      protected void doTextSeek(org.apache.sshd.common.util.buffer.Buffer buffer, int id) throws IOException
      Throws:
      IOException
    • doTextSeek

      protected abstract void doTextSeek(int id, String handle, long line) throws IOException
      Throws:
      IOException
    • doOpenSSHFsync

      protected void doOpenSSHFsync(org.apache.sshd.common.util.buffer.Buffer buffer, int id) throws IOException
      Throws:
      IOException
    • doOpenSSHFsync

      protected abstract void doOpenSSHFsync(int id, String handle) throws IOException
      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, org.apache.sshd.common.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 identifier
      path - Referenced path
      Returns:
      A "pair" containing the local link Path and 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

      protected void doRename(int id, String oldPath, String newPath, int flags) throws IOException
      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

      protected void doBlock(org.apache.sshd.common.util.buffer.Buffer buffer, int id) throws IOException
      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

      protected void doStat(org.apache.sshd.common.util.buffer.Buffer buffer, int id) throws IOException
      Throws:
      IOException
    • doStat

      protected Map<String,Object> doStat(int id, String path, int flags) throws IOException
      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 identifier
      path - The original path
      f - The resolve Path
      options - The LinkOptions to use to verify file existence and access
      Returns:
      A AbstractMap.SimpleImmutableEntry whose key is the absolute normalized Path and value is a Boolean indicating its status
      Throws:
      IOException - If failed to validate the file
      See Also:
      • IoUtils.checkFileExists(Path, LinkOption...)
    • doRemoveDirectory

      protected void doRemoveDirectory(org.apache.sshd.common.util.buffer.Buffer buffer, int id) throws IOException
      Throws:
      IOException
    • doRemoveDirectory

      protected void doRemoveDirectory(int id, String path) throws IOException
      Throws:
      IOException
    • doRemove

      protected void doRemove(int id, Path p, boolean isDirectory) throws IOException
      Called when need to delete a file / directory - also informs the SftpEventListener
      Parameters:
      id - Deletion request ID
      p - Path to delete
      isDirectory - 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

      protected void doMakeDirectory(int id, String path, Map<String,?> attrs) throws IOException
      Throws:
      IOException
    • doRemove

      protected void doRemove(org.apache.sshd.common.util.buffer.Buffer buffer, int id) throws IOException
      Throws:
      IOException
    • doRemoveFile

      protected void doRemoveFile(int id, String path) throws IOException
      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 command Buffer
      id - The request id
      extension - 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, org.apache.sshd.server.session.ServerSession session)
    • resolveAclSupportedCapabilities

      protected Collection<Integer> resolveAclSupportedCapabilities(org.apache.sshd.server.session.ServerSession session)
    • appendOpenSSHExtensions

      protected List<AbstractOpenSSHExtensionParser.OpenSSHExtension> appendOpenSSHExtensions(org.apache.sshd.common.util.buffer.Buffer buffer, org.apache.sshd.server.session.ServerSession session)
    • resolveOpenSSHExtensions

      protected List<AbstractOpenSSHExtensionParser.OpenSSHExtension> resolveOpenSSHExtensions(org.apache.sshd.server.session.ServerSession session)
    • getSupportedClientExtensions

      protected Map<String,org.apache.sshd.common.OptionalFeature> getSupportedClientExtensions(org.apache.sshd.server.session.ServerSession session)
    • appendVersionsExtension

      protected String appendVersionsExtension(org.apache.sshd.common.util.buffer.Buffer buffer, String value, org.apache.sshd.server.session.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 - The Buffer to append to
      value - The recommended value - ignored if null/empty
      session - The ServerSession for which this extension is added
      Returns:
      The apended value
      See Also:
    • appendNewlineExtension

      protected String appendNewlineExtension(org.apache.sshd.common.util.buffer.Buffer buffer, org.apache.sshd.server.session.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 - The Buffer to append to
      session - The ServerSession for which this extension is added
      Returns:
      The appended value
      See Also:
    • resolveNewlineValue

      protected String resolveNewlineValue(org.apache.sshd.server.session.ServerSession session)
    • appendVendorIdExtension

      protected Map<String,?> appendVendorIdExtension(org.apache.sshd.common.util.buffer.Buffer buffer, Map<String,?> versionProperties, org.apache.sshd.server.session.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 - The Buffer to append to
      versionProperties - The currently available version properties - ignored if null/empty. The code expects the following values:
      • groupId - as the vendor name
      • artifactId - as the product name
      • version - as the product version
      session - The ServerSession for 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 - The Buffer to append to
      extras - The extra extensions that are available and can be reported - may be null/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 - The Buffer to append to
      extras - The extra extensions that are available and can be reported - may be null/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 id
      handle - The (opaque) handle assigned to this directory
      dir - The DirectoryHandle
      buffer - The Buffer to write the results
      maxSize - Max. buffer size
      followLinks - 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(org.apache.sshd.server.session.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 id
      dir - The DirectoryHandle
      entries - An in / out Map for updating the written entry - key = short name, value = entry Path
      buffer - The Buffer to write the results
      index - Zero-based index of the entry to be written
      f - The entry Path
      shortName - The entry short name
      options - The LinkOptions to use for querying the entry-s attributes
      Throws:
      IOException - If failed to generate the entry data
    • getLongName

      protected String getLongName(Path f, String shortName, LinkOption... options) throws IOException
      Throws:
      IOException
    • getLongName

      protected String getLongName(Path f, String shortName, boolean sendAttrs, LinkOption... options) throws IOException
      Throws:
      IOException
    • getLongName

      protected String getLongName(Path f, String shortName, Map<String,?> attributes) throws IOException
      Throws:
      IOException
    • getLongName

      protected String getLongName(Path f, String shortName, SftpClient.Attributes attributes) throws IOException
      Throws:
      IOException
    • getShortName

      protected String getShortName(Path f) throws IOException
      Throws:
      IOException
    • resolveFileAttributes

      protected NavigableMap<String,Object> resolveFileAttributes(Path path, int flags, boolean neverFollowSymLinks, LinkOption... options) throws IOException
      Throws:
      IOException
    • checkSymlinkState

      public Boolean checkSymlinkState(Path path, boolean neverFollowSymLinks, LinkOption[] options)
      A utility function to validate that the directories leading up to a file are not symlinks
      Parameters:
      path - the file to check for symlink presence
      neverFollowSymLinks - whether to never follow symlinks in the parent paths
      options - whether the file itself can be a symlink
      Returns:
      whether there are symlinks in the path to this file, or null if unknown
    • validateParentExistWithNoSymlinksIfNeverFollowSymlinks

      public Boolean validateParentExistWithNoSymlinksIfNeverFollowSymlinks(Path path, boolean neverFollowSymLinks)
    • writeAttrs

      protected void writeAttrs(org.apache.sshd.common.util.buffer.Buffer buffer, Map<String,?> attributes)
    • 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 - The Path location for the required attributes
      flags - A mask of the original required attributes - ignored by the default implementation
      options - The LinkOptions to use in order to access the file if necessary
      Returns:
      A Map of 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 IOException
      Called by getAttributes(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 - The Path location for the required attributes
      flags - A mask of the original required attributes - ignored by the default implementation
      current - The Map of attributes already retrieved - may be null/empty and/or unmodifiable
      options - The LinkOptions to use in order to access the file if necessary
      Returns:
      A Map of 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-null value
      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
    • addMissingAttribute

      protected NavigableMap<String,Object> addMissingAttribute(Path file, NavigableMap<String,Object> current, String name, 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

      protected void handleUnsupportedAttributes(Collection<String> attributes)
    • toGroup

      protected GroupPrincipal toGroup(Path file, GroupPrincipal name) throws IOException
      Throws:
      IOException
    • toUser

      protected UserPrincipal toUser(Path file, UserPrincipal name) throws IOException
      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 id
      h - The resolved Handle instance
      type - The expected handle type
      Returns:
      The cast type
      Throws:
      IOException - If a generic exception occurred
      FileNotFoundException - If the handle instance is null
      InvalidHandleException - 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 - A Buffer to be used to build the status reply
      id - Command identifier
      e - Thrown exception
      cmd - The command that was attempted
      args - 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

      protected abstract void send(org.apache.sshd.common.util.buffer.Buffer buffer) throws IOException
      Throws:
      IOException
    • resolveNormalizedLocation

      protected Path resolveNormalizedLocation(String remotePath) throws IOException, InvalidPathException
      Throws:
      IOException
      InvalidPathException
    • normalize

      protected Path normalize(Path f)
    • resolveFile

      protected Path resolveFile(String remotePath) throws IOException, InvalidPathException
      Parameters:
      remotePath - The remote path - separated by '/'
      Returns:
      The local Path
      Throws:
      IOException - If failed to resolve the local path
      InvalidPathException - If bad local path specification