Class AbstractSftpSubsystemHelper

    • Field Detail

      • DEFAULT_SUPPORTED_CLIENT_EXTENSIONS

        public static final java.util.NavigableMap<java.lang.String,​OptionalFeature> DEFAULT_SUPPORTED_CLIENT_EXTENSIONS
        The default reported supported client extensions (case insensitive)
      • OPENSSH_EXTENSIONS_PROP

        public static final java.lang.String OPENSSH_EXTENSIONS_PROP
        Comma-separated list of which OpenSSH extensions are reported and what version is reported for each - format: name=version. If empty value set, then no such extensions are reported. Otherwise, the DEFAULT_OPEN_SSH_EXTENSIONS are used
        See Also:
        Constant Field Values
      • DEFAULT_OPEN_SSH_EXTENSIONS_NAMES

        public static final java.util.List<java.lang.String> DEFAULT_OPEN_SSH_EXTENSIONS_NAMES
      • ACL_SUPPORTED_MASK_PROP

        public static final java.lang.String ACL_SUPPORTED_MASK_PROP
        Comma separate list of SSH_ACL_CAP_xxx names - where name can be without the prefix. If not defined then DEFAULT_ACL_SUPPORTED_MASK is used
        See Also:
        Constant Field Values
      • DEFAULT_ACL_SUPPORTED_MASK

        public static final java.util.Set<java.lang.Integer> DEFAULT_ACL_SUPPORTED_MASK
      • NEWLINE_VALUE

        public static final java.lang.String NEWLINE_VALUE
        Property that can be used to set the reported NL value. If not set, then IoUtils.EOL is used
        See Also:
        Constant Field Values
      • DEFAULT_MAX_READDATA_PACKET_LENGTH

        public static final int DEFAULT_MAX_READDATA_PACKET_LENGTH
        See Also:
        Constant Field Values
      • sftpEventListeners

        private final java.util.Collection<SftpEventListener> sftpEventListeners
    • Method Detail

      • validateProposedVersion

        protected java.lang.Boolean validateProposedVersion​(Buffer buffer,
                                                            int id,
                                                            java.lang.String proposal)
                                                     throws java.io.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:
        java.io.IOException - If failed send an independent rejection response
      • checkVersionCompatibility

        protected java.util.Map.Entry<java.lang.Integer,​java.lang.String> checkVersionCompatibility​(Buffer buffer,
                                                                                                          int id,
                                                                                                          int proposed,
                                                                                                          int failureOpcode)
                                                                                                   throws java.io.IOException
        Checks if a proposed version is within supported range. Note: if the user forced a specific value via the SftpSubsystemEnvironment.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:
        java.io.IOException - If failed to send the failure status message
      • process

        protected void process​(Buffer buffer)
                        throws java.io.IOException
        Process an SFTP command. If the command throws an exception, the channel will be closed.
        Parameters:
        buffer - the buffer to process
        Throws:
        java.io.IOException - if anything wrong happens
      • doProcess

        protected void doProcess​(Buffer buffer,
                                 int length,
                                 int type,
                                 int id)
                          throws java.io.IOException
        Throws:
        java.io.IOException
      • doUnsupported

        protected void doUnsupported​(Buffer buffer,
                                     int length,
                                     int type,
                                     int id)
                              throws java.io.IOException
        Throws:
        java.io.IOException
      • doInit

        protected abstract void doInit​(Buffer buffer,
                                       int id)
                                throws java.io.IOException
        Throws:
        java.io.IOException
      • doVersionSelect

        protected void doVersionSelect​(Buffer buffer,
                                       int id)
                                throws java.io.IOException
        Throws:
        java.io.IOException
      • doVersionSelect

        protected abstract void doVersionSelect​(Buffer buffer,
                                                int id,
                                                java.lang.String proposed)
                                         throws java.io.IOException
        Throws:
        java.io.IOException
      • doOpen

        protected void doOpen​(Buffer buffer,
                              int id)
                       throws java.io.IOException
        Throws:
        java.io.IOException
      • doOpen

        protected abstract java.lang.String doOpen​(int id,
                                                   java.lang.String path,
                                                   int pflags,
                                                   int access,
                                                   java.util.Map<java.lang.String,​java.lang.Object> attrs)
                                            throws java.io.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:
        java.io.IOException - if failed to execute
      • signalOpenFailure

        protected <E extends java.io.IOException> E signalOpenFailure​(int id,
                                                                      java.lang.String pathValue,
                                                                      java.nio.file.Path path,
                                                                      boolean isDir,
                                                                      E thrown)
                                                               throws java.io.IOException
        Throws:
        java.io.IOException
      • doClose

        protected void doClose​(Buffer buffer,
                               int id)
                        throws java.io.IOException
        Throws:
        java.io.IOException
      • doClose

        protected abstract void doClose​(int id,
                                        java.lang.String handle)
                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • doRead

        protected void doRead​(Buffer buffer,
                              int id)
                       throws java.io.IOException
        Throws:
        java.io.IOException
      • doRead

        protected abstract int doRead​(int id,
                                      java.lang.String handle,
                                      long offset,
                                      int length,
                                      byte[] data,
                                      int doff)
                               throws java.io.IOException
        Throws:
        java.io.IOException
      • doWrite

        protected void doWrite​(Buffer buffer,
                               int id)
                        throws java.io.IOException
        Throws:
        java.io.IOException
      • doWrite

        protected abstract void doWrite​(int id,
                                        java.lang.String handle,
                                        long offset,
                                        int length,
                                        byte[] data,
                                        int doff,
                                        int remaining)
                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • doLStat

        protected void doLStat​(Buffer buffer,
                               int id)
                        throws java.io.IOException
        Throws:
        java.io.IOException
      • doLStat

        protected java.util.Map<java.lang.String,​java.lang.Object> doLStat​(int id,
                                                                                 java.lang.String path,
                                                                                 int flags)
                                                                          throws java.io.IOException
        Throws:
        java.io.IOException
      • doSetStat

        protected void doSetStat​(Buffer buffer,
                                 int id,
                                 java.lang.String extension,
                                 int cmd,
                                 java.lang.Boolean followLinks)
                          throws java.io.IOException
        Throws:
        java.io.IOException
      • doSetStat

        protected void doSetStat​(int id,
                                 java.lang.String path,
                                 int cmd,
                                 java.lang.String extension,
                                 java.util.Map<java.lang.String,​?> attrs,
                                 java.lang.Boolean followLinks)
                          throws java.io.IOException
        Throws:
        java.io.IOException
      • doFStat

        protected void doFStat​(Buffer buffer,
                               int id)
                        throws java.io.IOException
        Throws:
        java.io.IOException
      • doFStat

        protected abstract java.util.Map<java.lang.String,​java.lang.Object> doFStat​(int id,
                                                                                          java.lang.String handle,
                                                                                          int flags)
                                                                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • doFSetStat

        protected void doFSetStat​(Buffer buffer,
                                  int id)
                           throws java.io.IOException
        Throws:
        java.io.IOException
      • doFSetStat

        protected abstract void doFSetStat​(int id,
                                           java.lang.String handle,
                                           java.util.Map<java.lang.String,​?> attrs)
                                    throws java.io.IOException
        Throws:
        java.io.IOException
      • doOpenDir

        protected void doOpenDir​(Buffer buffer,
                                 int id)
                          throws java.io.IOException
        Throws:
        java.io.IOException
      • doOpenDir

        protected abstract java.lang.String doOpenDir​(int id,
                                                      java.lang.String path,
                                                      java.nio.file.Path p,
                                                      java.nio.file.LinkOption... options)
                                               throws java.io.IOException
        Throws:
        java.io.IOException
      • doReadDir

        protected abstract void doReadDir​(Buffer buffer,
                                          int id)
                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • doLink

        protected void doLink​(Buffer buffer,
                              int id)
                       throws java.io.IOException
        Throws:
        java.io.IOException
      • doLink

        protected void doLink​(int id,
                              java.lang.String targetPath,
                              java.lang.String linkPath,
                              boolean symLink)
                       throws java.io.IOException
        Throws:
        java.io.IOException
      • doSymLink

        protected void doSymLink​(Buffer buffer,
                                 int id)
                          throws java.io.IOException
        Throws:
        java.io.IOException
      • doSymLink

        protected void doSymLink​(int id,
                                 java.lang.String targetPath,
                                 java.lang.String linkPath)
                          throws java.io.IOException
        Throws:
        java.io.IOException
      • createLink

        protected abstract void createLink​(int id,
                                           java.lang.String existingPath,
                                           java.lang.String linkPath,
                                           boolean symLink)
                                    throws java.io.IOException
        Throws:
        java.io.IOException
      • doOpenSSHHardLink

        protected void doOpenSSHHardLink​(Buffer buffer,
                                         int id)
                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • doOpenSSHHardLink

        protected void doOpenSSHHardLink​(int id,
                                         java.lang.String srcFile,
                                         java.lang.String dstFile)
                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • doSpaceAvailable

        protected void doSpaceAvailable​(Buffer buffer,
                                        int id)
                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • doSpaceAvailable

        protected SpaceAvailableExtensionInfo doSpaceAvailable​(int id,
                                                               java.lang.String path)
                                                        throws java.io.IOException
        Throws:
        java.io.IOException
      • doTextSeek

        protected void doTextSeek​(Buffer buffer,
                                  int id)
                           throws java.io.IOException
        Throws:
        java.io.IOException
      • doTextSeek

        protected abstract void doTextSeek​(int id,
                                           java.lang.String handle,
                                           long line)
                                    throws java.io.IOException
        Throws:
        java.io.IOException
      • doOpenSSHFsync

        protected void doOpenSSHFsync​(Buffer buffer,
                                      int id)
                               throws java.io.IOException
        Throws:
        java.io.IOException
      • doOpenSSHFsync

        protected abstract void doOpenSSHFsync​(int id,
                                               java.lang.String handle)
                                        throws java.io.IOException
        Throws:
        java.io.IOException
      • doCheckFileHash

        protected void doCheckFileHash​(Buffer buffer,
                                       int id,
                                       java.lang.String targetType)
                                throws java.io.IOException
        Throws:
        java.io.IOException
      • doCheckFileHash

        protected void doCheckFileHash​(int id,
                                       java.nio.file.Path file,
                                       NamedFactory<? extends Digest> factory,
                                       long startOffset,
                                       long length,
                                       int blockSize,
                                       Buffer buffer)
                                throws java.lang.Exception
        Throws:
        java.lang.Exception
      • doMD5Hash

        protected void doMD5Hash​(Buffer buffer,
                                 int id,
                                 java.lang.String targetType)
                          throws java.io.IOException
        Throws:
        java.io.IOException
      • doMD5Hash

        protected abstract byte[] doMD5Hash​(int id,
                                            java.lang.String targetType,
                                            java.lang.String target,
                                            long startOffset,
                                            long length,
                                            byte[] quickCheckHash)
                                     throws java.lang.Exception
        Throws:
        java.lang.Exception
      • doMD5Hash

        protected byte[] doMD5Hash​(int id,
                                   java.nio.file.Path path,
                                   long startOffset,
                                   long length,
                                   byte[] quickCheckHash)
                            throws java.lang.Exception
        Throws:
        java.lang.Exception
      • doCheckFileHash

        protected abstract void doCheckFileHash​(int id,
                                                java.lang.String targetType,
                                                java.lang.String target,
                                                java.util.Collection<java.lang.String> algos,
                                                long startOffset,
                                                long length,
                                                int blockSize,
                                                Buffer buffer)
                                         throws java.lang.Exception
        Throws:
        java.lang.Exception
      • doReadLink

        protected void doReadLink​(Buffer buffer,
                                  int id)
                           throws java.io.IOException
        Throws:
        java.io.IOException
      • doReadLink

        protected java.lang.String doReadLink​(int id,
                                              java.lang.String path)
                                       throws java.io.IOException
        Throws:
        java.io.IOException
      • doRename

        protected void doRename​(Buffer buffer,
                                int id)
                         throws java.io.IOException
        Throws:
        java.io.IOException
      • doRename

        protected void doRename​(int id,
                                java.lang.String oldPath,
                                java.lang.String newPath,
                                int flags)
                         throws java.io.IOException
        Throws:
        java.io.IOException
      • doRename

        protected void doRename​(int id,
                                java.lang.String oldPath,
                                java.lang.String newPath,
                                java.util.Collection<java.nio.file.CopyOption> opts)
                         throws java.io.IOException
        Throws:
        java.io.IOException
      • doCopyData

        protected void doCopyData​(Buffer buffer,
                                  int id)
                           throws java.io.IOException
        Throws:
        java.io.IOException
      • doCopyData

        protected abstract void doCopyData​(int id,
                                           java.lang.String readHandle,
                                           long readOffset,
                                           long readLength,
                                           java.lang.String writeHandle,
                                           long writeOffset)
                                    throws java.io.IOException
        Throws:
        java.io.IOException
      • doCopyFile

        protected void doCopyFile​(Buffer buffer,
                                  int id)
                           throws java.io.IOException
        Throws:
        java.io.IOException
      • doCopyFile

        protected void doCopyFile​(int id,
                                  java.lang.String srcFile,
                                  java.lang.String dstFile,
                                  boolean overwriteDestination)
                           throws java.io.IOException
        Throws:
        java.io.IOException
      • doCopyFile

        protected void doCopyFile​(int id,
                                  java.lang.String srcFile,
                                  java.lang.String dstFile,
                                  java.util.Collection<java.nio.file.CopyOption> opts)
                           throws java.io.IOException
        Throws:
        java.io.IOException
      • doBlock

        protected void doBlock​(Buffer buffer,
                               int id)
                        throws java.io.IOException
        Throws:
        java.io.IOException
      • doBlock

        protected abstract void doBlock​(int id,
                                        java.lang.String handle,
                                        long offset,
                                        long length,
                                        int mask)
                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • doUnblock

        protected void doUnblock​(Buffer buffer,
                                 int id)
                          throws java.io.IOException
        Throws:
        java.io.IOException
      • doUnblock

        protected abstract void doUnblock​(int id,
                                          java.lang.String handle,
                                          long offset,
                                          long length)
                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • doStat

        protected void doStat​(Buffer buffer,
                              int id)
                       throws java.io.IOException
        Throws:
        java.io.IOException
      • doStat

        protected java.util.Map<java.lang.String,​java.lang.Object> doStat​(int id,
                                                                                java.lang.String path,
                                                                                int flags)
                                                                         throws java.io.IOException
        Throws:
        java.io.IOException
      • doRealPath

        protected void doRealPath​(Buffer buffer,
                                  int id)
                           throws java.io.IOException
        Throws:
        java.io.IOException
      • doRealPathV6

        protected java.util.AbstractMap.SimpleImmutableEntry<java.nio.file.Path,​java.lang.Boolean> doRealPathV6​(int id,
                                                                                                                      java.lang.String path,
                                                                                                                      java.util.Collection<java.lang.String> extraPaths,
                                                                                                                      java.nio.file.Path p,
                                                                                                                      java.nio.file.LinkOption... options)
                                                                                                               throws java.io.IOException
        Throws:
        java.io.IOException
      • doRealPathV345

        protected java.util.AbstractMap.SimpleImmutableEntry<java.nio.file.Path,​java.lang.Boolean> doRealPathV345​(int id,
                                                                                                                        java.lang.String path,
                                                                                                                        java.nio.file.Path p,
                                                                                                                        java.nio.file.LinkOption... options)
                                                                                                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • validateRealPath

        protected java.util.AbstractMap.SimpleImmutableEntry<java.nio.file.Path,​java.lang.Boolean> validateRealPath​(int id,
                                                                                                                          java.lang.String path,
                                                                                                                          java.nio.file.Path f,
                                                                                                                          java.nio.file.LinkOption... options)
                                                                                                                   throws java.io.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:
        java.io.IOException - If failed to validate the file
        See Also:
        IoUtils.checkFileExists(Path, LinkOption...)
      • doRemoveDirectory

        protected void doRemoveDirectory​(Buffer buffer,
                                         int id)
                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • doRemoveDirectory

        protected void doRemoveDirectory​(int id,
                                         java.lang.String path,
                                         java.nio.file.LinkOption... options)
                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • doRemove

        protected void doRemove​(int id,
                                java.nio.file.Path p,
                                boolean isDirectory)
                         throws java.io.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:
        java.io.IOException - If failed to delete
      • doMakeDirectory

        protected void doMakeDirectory​(Buffer buffer,
                                       int id)
                                throws java.io.IOException
        Throws:
        java.io.IOException
      • doMakeDirectory

        protected void doMakeDirectory​(int id,
                                       java.lang.String path,
                                       java.util.Map<java.lang.String,​?> attrs,
                                       java.nio.file.LinkOption... options)
                                throws java.io.IOException
        Throws:
        java.io.IOException
      • doRemove

        protected void doRemove​(Buffer buffer,
                                int id)
                         throws java.io.IOException
        Throws:
        java.io.IOException
      • doRemove

        protected void doRemove​(int id,
                                java.lang.String path,
                                java.nio.file.LinkOption... options)
                         throws java.io.IOException
        Throws:
        java.io.IOException
      • signalRemovalPreConditionFailure

        protected <E extends java.io.IOException> E signalRemovalPreConditionFailure​(int id,
                                                                                     java.lang.String pathValue,
                                                                                     java.nio.file.Path path,
                                                                                     E thrown,
                                                                                     boolean isRemoveDirectory)
                                                                              throws java.io.IOException
        Throws:
        java.io.IOException
      • doExtended

        protected void doExtended​(Buffer buffer,
                                  int id)
                           throws java.io.IOException
        Throws:
        java.io.IOException
      • executeExtendedCommand

        protected void executeExtendedCommand​(Buffer buffer,
                                              int id,
                                              java.lang.String extension)
                                       throws java.io.IOException
        Parameters:
        buffer - The command Buffer
        id - The request id
        extension - The extension name
        Throws:
        java.io.IOException - If failed to execute the extension
      • doUnsupportedExtension

        protected void doUnsupportedExtension​(Buffer buffer,
                                              int id,
                                              java.lang.String extension)
                                       throws java.io.IOException
        Throws:
        java.io.IOException
      • appendExtensions

        protected void appendExtensions​(Buffer buffer,
                                        java.lang.String supportedVersions)
      • appendAclSupportedExtension

        protected int appendAclSupportedExtension​(Buffer buffer,
                                                  ServerSession session)
      • resolveAclSupportedCapabilities

        protected java.util.Collection<java.lang.Integer> resolveAclSupportedCapabilities​(ServerSession session)
      • getSupportedClientExtensions

        protected java.util.Map<java.lang.String,​OptionalFeature> getSupportedClientExtensions​(ServerSession session)
      • appendVersionsExtension

        protected void appendVersionsExtension​(Buffer buffer,
                                               java.lang.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 - The Buffer to append to
        value - The recommended value - ignored if null/empty
        session - The ServerSession for which this extension is added
        See Also:
        SftpConstants.EXT_VERSIONS
      • resolveNewlineValue

        protected java.lang.String resolveNewlineValue​(ServerSession session)
      • appendVendorIdExtension

        protected void appendVendorIdExtension​(Buffer buffer,
                                               java.util.Map<java.lang.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 - 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
        See Also:
        SftpConstants.EXT_VENDOR_ID, DRAFT 09 - section 4.4
      • appendSupportedExtension

        protected void appendSupportedExtension​(Buffer buffer,
                                                java.util.Collection<java.lang.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​(Buffer buffer,
                                                 java.util.Collection<java.lang.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:
        SftpConstants.EXT_SUPPORTED, DRAFT 13 section 5.4
      • sendHandle

        protected void sendHandle​(Buffer buffer,
                                  int id,
                                  java.lang.String handle)
                           throws java.io.IOException
        Throws:
        java.io.IOException
      • sendAttrs

        protected void sendAttrs​(Buffer buffer,
                                 int id,
                                 java.util.Map<java.lang.String,​?> attributes)
                          throws java.io.IOException
        Throws:
        java.io.IOException
      • sendLink

        protected void sendLink​(Buffer buffer,
                                int id,
                                java.lang.String link)
                         throws java.io.IOException
        Throws:
        java.io.IOException
      • sendPath

        protected void sendPath​(Buffer buffer,
                                int id,
                                java.nio.file.Path f,
                                java.util.Map<java.lang.String,​?> attrs)
                         throws java.io.IOException
        Throws:
        java.io.IOException
      • doReadDir

        protected int doReadDir​(int id,
                                java.lang.String handle,
                                DirectoryHandle dir,
                                Buffer buffer,
                                int maxSize,
                                java.nio.file.LinkOption... options)
                         throws java.io.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
        options - The LinkOption-s to use when querying the directory contents
        Returns:
        Number of written entries
        Throws:
        java.io.IOException - If failed to generate an entry
      • writeDirEntry

        protected void writeDirEntry​(int id,
                                     DirectoryHandle dir,
                                     java.util.Map<java.lang.String,​java.nio.file.Path> entries,
                                     Buffer buffer,
                                     int index,
                                     java.nio.file.Path f,
                                     java.lang.String shortName,
                                     java.nio.file.LinkOption... options)
                              throws java.io.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:
        java.io.IOException - If failed to generate the entry data
      • getLongName

        protected java.lang.String getLongName​(java.nio.file.Path f,
                                               java.lang.String shortName,
                                               java.nio.file.LinkOption... options)
                                        throws java.io.IOException
        Throws:
        java.io.IOException
      • getLongName

        protected java.lang.String getLongName​(java.nio.file.Path f,
                                               java.lang.String shortName,
                                               boolean sendAttrs,
                                               java.nio.file.LinkOption... options)
                                        throws java.io.IOException
        Throws:
        java.io.IOException
      • getLongName

        protected java.lang.String getLongName​(java.nio.file.Path f,
                                               java.lang.String shortName,
                                               java.util.Map<java.lang.String,​?> attributes)
                                        throws java.io.IOException
        Throws:
        java.io.IOException
      • getShortName

        protected java.lang.String getShortName​(java.nio.file.Path f)
                                         throws java.io.IOException
        Throws:
        java.io.IOException
      • resolveFileAttributes

        protected java.util.NavigableMap<java.lang.String,​java.lang.Object> resolveFileAttributes​(java.nio.file.Path file,
                                                                                                        int flags,
                                                                                                        java.nio.file.LinkOption... options)
                                                                                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • writeAttrs

        protected void writeAttrs​(Buffer buffer,
                                  java.util.Map<java.lang.String,​?> attributes)
                           throws java.io.IOException
        Throws:
        java.io.IOException
      • getAttributes

        protected java.util.NavigableMap<java.lang.String,​java.lang.Object> getAttributes​(java.nio.file.Path file,
                                                                                                java.nio.file.LinkOption... options)
                                                                                         throws java.io.IOException
        Throws:
        java.io.IOException
      • handleUnknownStatusFileAttributes

        protected java.util.NavigableMap<java.lang.String,​java.lang.Object> handleUnknownStatusFileAttributes​(java.nio.file.Path file,
                                                                                                                    int flags,
                                                                                                                    java.nio.file.LinkOption... options)
                                                                                                             throws java.io.IOException
        Throws:
        java.io.IOException
      • getAttributes

        protected java.util.NavigableMap<java.lang.String,​java.lang.Object> getAttributes​(java.nio.file.Path file,
                                                                                                int flags,
                                                                                                java.nio.file.LinkOption... options)
                                                                                         throws java.io.IOException
        Parameters:
        file - 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:
        java.io.IOException - If failed to access the file
        See Also:
        resolveMissingFileAttributes(Path, int, Map, LinkOption...)
      • resolveMissingFileAttributes

        protected java.util.NavigableMap<java.lang.String,​java.lang.Object> resolveMissingFileAttributes​(java.nio.file.Path file,
                                                                                                               int flags,
                                                                                                               java.util.Map<java.lang.String,​java.lang.Object> current,
                                                                                                               java.nio.file.LinkOption... options)
                                                                                                        throws java.io.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:
        java.io.IOException - If failed to access the attributes - in which case an error is returned to the SFTP client
        See Also:
        SftpFileSystemAccessor.FILEATTRS_RESOLVERS
      • resolveMissingFileAttributeValue

        protected java.lang.Object resolveMissingFileAttributeValue​(java.nio.file.Path file,
                                                                    java.lang.String name,
                                                                    java.lang.Object value,
                                                                    FileInfoExtractor<?> x,
                                                                    java.nio.file.LinkOption... options)
                                                             throws java.io.IOException
        Throws:
        java.io.IOException
      • addMissingAttribute

        protected java.util.NavigableMap<java.lang.String,​java.lang.Object> addMissingAttribute​(java.nio.file.Path file,
                                                                                                      java.util.NavigableMap<java.lang.String,​java.lang.Object> current,
                                                                                                      java.lang.String name,
                                                                                                      FileInfoExtractor<?> x,
                                                                                                      java.nio.file.LinkOption... options)
                                                                                               throws java.io.IOException
        Throws:
        java.io.IOException
      • readFileAttributes

        protected java.util.NavigableMap<java.lang.String,​java.lang.Object> readFileAttributes​(java.nio.file.Path file,
                                                                                                     java.lang.String view,
                                                                                                     java.nio.file.LinkOption... options)
                                                                                              throws java.io.IOException
        Throws:
        java.io.IOException
      • handleReadFileAttributesException

        protected java.util.NavigableMap<java.lang.String,​java.lang.Object> handleReadFileAttributesException​(java.nio.file.Path file,
                                                                                                                    java.lang.String view,
                                                                                                                    java.nio.file.LinkOption[] options,
                                                                                                                    java.io.IOException e)
                                                                                                             throws java.io.IOException
        Throws:
        java.io.IOException
      • doSetAttributes

        protected void doSetAttributes​(java.nio.file.Path file,
                                       java.util.Map<java.lang.String,​?> attributes,
                                       boolean followLinks)
                                throws java.io.IOException
        Throws:
        java.io.IOException
      • getPathResolutionLinkOption

        protected java.nio.file.LinkOption[] getPathResolutionLinkOption​(int cmd,
                                                                         java.lang.String extension,
                                                                         java.nio.file.Path path)
                                                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • resolvePathResolutionFollowLinks

        protected boolean resolvePathResolutionFollowLinks​(int cmd,
                                                           java.lang.String extension,
                                                           java.nio.file.Path path)
                                                    throws java.io.IOException
        Throws:
        java.io.IOException
      • setFileAttributes

        protected void setFileAttributes​(java.nio.file.Path file,
                                         java.util.Map<java.lang.String,​?> attributes,
                                         java.nio.file.LinkOption... options)
                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • handleSetFileAttributeFailure

        protected void handleSetFileAttributeFailure​(java.nio.file.Path file,
                                                     java.lang.String view,
                                                     java.lang.String attribute,
                                                     java.lang.Object value,
                                                     java.util.Collection<java.lang.String> unsupported,
                                                     java.lang.Exception e)
                                              throws java.io.IOException
        Throws:
        java.io.IOException
      • setFileAttribute

        protected void setFileAttribute​(java.nio.file.Path file,
                                        java.lang.String view,
                                        java.lang.String attribute,
                                        java.lang.Object value,
                                        java.nio.file.LinkOption... options)
                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • setFileTime

        protected void setFileTime​(java.nio.file.Path file,
                                   java.lang.String view,
                                   java.lang.String attribute,
                                   java.nio.file.attribute.FileTime value,
                                   java.nio.file.LinkOption... options)
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • setFileOwnership

        protected void setFileOwnership​(java.nio.file.Path file,
                                        java.lang.String attribute,
                                        java.security.Principal value,
                                        java.nio.file.LinkOption... options)
                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • setFileExtensions

        protected void setFileExtensions​(java.nio.file.Path file,
                                         java.util.Map<java.lang.String,​byte[]> extensions,
                                         java.nio.file.LinkOption... options)
                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • setFilePermissions

        protected void setFilePermissions​(java.nio.file.Path file,
                                          java.util.Set<java.nio.file.attribute.PosixFilePermission> perms,
                                          java.nio.file.LinkOption... options)
                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • setFileAccessControl

        protected void setFileAccessControl​(java.nio.file.Path file,
                                            java.util.List<java.nio.file.attribute.AclEntry> acl,
                                            java.nio.file.LinkOption... options)
                                     throws java.io.IOException
        Throws:
        java.io.IOException
      • handleUnsupportedAttributes

        protected void handleUnsupportedAttributes​(java.util.Collection<java.lang.String> attributes)
      • toGroup

        protected java.nio.file.attribute.GroupPrincipal toGroup​(java.nio.file.Path file,
                                                                 java.nio.file.attribute.GroupPrincipal name)
                                                          throws java.io.IOException
        Throws:
        java.io.IOException
      • toUser

        protected java.nio.file.attribute.UserPrincipal toUser​(java.nio.file.Path file,
                                                               java.nio.file.attribute.UserPrincipal name)
                                                        throws java.io.IOException
        Throws:
        java.io.IOException
      • handleUserPrincipalLookupServiceException

        protected void handleUserPrincipalLookupServiceException​(java.lang.Class<? extends java.security.Principal> principalType,
                                                                 java.lang.String name,
                                                                 java.io.IOException e)
                                                          throws java.io.IOException
        Throws:
        java.io.IOException
      • readAttrs

        protected java.util.Map<java.lang.String,​java.lang.Object> readAttrs​(Buffer buffer)
                                                                            throws java.io.IOException
        Throws:
        java.io.IOException
      • validateHandle

        protected <H extends Handle> H validateHandle​(java.lang.String handle,
                                                      Handle h,
                                                      java.lang.Class<H> type)
                                               throws java.io.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:
        java.io.IOException - If a generic exception occurred
        java.io.FileNotFoundException - If the handle instance is null
        InvalidHandleException - If the handle instance is not of the expected type
      • sendStatus

        protected void sendStatus​(Buffer buffer,
                                  int id,
                                  java.lang.Throwable e,
                                  int cmd,
                                  java.lang.Object... args)
                           throws java.io.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:
        java.io.IOException - If failed to build and send the status buffer
      • sendStatus

        protected void sendStatus​(Buffer buffer,
                                  int id,
                                  int substatus,
                                  java.lang.String msg)
                           throws java.io.IOException
        Throws:
        java.io.IOException
      • sendStatus

        protected void sendStatus​(Buffer buffer,
                                  int id,
                                  int substatus,
                                  java.lang.String msg,
                                  java.lang.String lang)
                           throws java.io.IOException
        Throws:
        java.io.IOException
      • prepareReply

        protected abstract Buffer prepareReply​(Buffer buffer)
      • send

        protected abstract void send​(Buffer buffer)
                              throws java.io.IOException
        Throws:
        java.io.IOException
      • resolveNormalizedLocation

        protected java.nio.file.Path resolveNormalizedLocation​(java.lang.String remotePath)
                                                        throws java.io.IOException,
                                                               java.nio.file.InvalidPathException
        Throws:
        java.io.IOException
        java.nio.file.InvalidPathException
      • normalize

        protected java.nio.file.Path normalize​(java.nio.file.Path f)
      • resolveFile

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