Class SftpFileSystem

    • Field Detail

      • LOG

        private static final org.apache.commons.logging.Log LOG
      • LAST_MOD_TIME_ACCURACY

        private static final long LAST_MOD_TIME_ACCURACY
        See Also:
        Constant Field Values
      • session

        private volatile com.jcraft.jsch.Session session
        Session; never null.

        DCL pattern requires that the ivar be volatile.

      • idleChannel

        private volatile com.jcraft.jsch.ChannelSftp idleChannel
      • connectTimeout

        private final java.time.Duration connectTimeout
      • uid

        private volatile int uid
        Cache for the user ID (-1 when not set)

        DCL pattern requires that the ivar be volatile.

      • groupsIds

        private volatile int[] groupsIds
        Cache for the user groups ids (null when not set)

        DCL pattern requires that the ivar be volatile.

      • execDisabled

        private final boolean execDisabled
        Some SFTP-only servers disable the exec channel. When exec is disabled, things like getUId() will always fail.
    • Method Detail

      • addCapabilities

        protected void addCapabilities​(java.util.Collection<Capability> caps)
        Adds the capabilities of this file system.
        Specified by:
        addCapabilities in class AbstractFileSystem
        Parameters:
        caps - collections of Capabilities, can be immutable.
      • detectExecDisabled

        private boolean detectExecDisabled()
        Some SFTP-only servers disable the exec channel. Attempt to detect this by calling getUid.
      • executeCommand

        private int executeCommand​(java.lang.String command,
                                   java.lang.StringBuilder output)
                            throws com.jcraft.jsch.JSchException,
                                   java.io.IOException
        Executes a command and returns the (standard) output through a StringBuilder.
        Parameters:
        command - The command
        output - The output
        Returns:
        The exit code of the command
        Throws:
        com.jcraft.jsch.JSchException - if a JSch error is detected.
        FileSystemException - if a session cannot be created.
        java.io.IOException - if an I/O error is detected.
      • getChannel

        protected com.jcraft.jsch.ChannelSftp getChannel()
                                                  throws java.io.IOException
        Returns an SFTP channel to the server.
        Returns:
        new or reused channel, never null.
        Throws:
        FileSystemException - if a session cannot be created.
        java.io.IOException - if an I/O error is detected.
      • getGroupsIds

        public int[] getGroupsIds()
                           throws com.jcraft.jsch.JSchException,
                                  java.io.IOException
        Gets the (numeric) group IDs.
        Returns:
        the (numeric) group IDs.
        Throws:
        com.jcraft.jsch.JSchException - If a problem occurs while retrieving the group IDs.
        java.io.IOException - if an I/O error is detected.
        Since:
        2.1
      • getSession

        private com.jcraft.jsch.Session getSession()
                                            throws FileSystemException
        Ensures that the session link is established.
        Throws:
        FileSystemException - if a session cannot be created.
      • getUId

        public int getUId()
                   throws com.jcraft.jsch.JSchException,
                          java.io.IOException
        Gets the (numeric) group IDs.
        Returns:
        The numeric user ID
        Throws:
        com.jcraft.jsch.JSchException - If a problem occurs while retrieving the group ID.
        java.io.IOException - if an I/O error is detected.
        Since:
        2.1
      • isExecDisabled

        public boolean isExecDisabled()
        Returns:
        Whether the exec channel is disabled.
        See Also:
        execDisabled
      • putChannel

        protected void putChannel​(com.jcraft.jsch.ChannelSftp channelSftp)
        Returns a channel to the pool.
        Parameters:
        channelSftp - the SFTP channel.