Class SFTPEnvironment

    • Constructor Detail

      • SFTPEnvironment

        public SFTPEnvironment()
        Creates a new SFTP environment.
      • SFTPEnvironment

        public SFTPEnvironment​(Map<String,​Object> map)
        Creates a new SFTP environment.
        Parameters:
        map - The map to wrap.
    • Method Detail

      • withUsername

        public SFTPEnvironment withUsername​(String username)
        Stores the username to use.
        Parameters:
        username - The username to use.
        Returns:
        This object.
      • withConnectTimeout

        @QueryParam("connectTimeout")
        public SFTPEnvironment withConnectTimeout​(int timeout)
        Stores the connection timeout to use.
        Parameters:
        timeout - The connection timeout in milliseconds.
        Returns:
        This object.
      • withProxy

        public SFTPEnvironment withProxy​(Proxy proxy)
        Stores the proxy to use.
        Parameters:
        proxy - The proxy to use.
        Returns:
        This object.
      • withUserInfo

        public SFTPEnvironment withUserInfo​(UserInfo userInfo)
        Stores the user info to use.
        Parameters:
        userInfo - The user info to use.
        Returns:
        This object.
      • withPassword

        public SFTPEnvironment withPassword​(char[] password)
        Stores the password to use.
        Parameters:
        password - The password to use.
        Returns:
        This object.
        Since:
        1.1
      • withConfig

        public SFTPEnvironment withConfig​(Properties config)
        Stores configuration options to use. This method will add not clear any previously set options, but only add new ones.
        Parameters:
        config - The configuration options to use.
        Returns:
        This object.
        Throws:
        NullPointerException - if the given properties object is null.
        See Also:
        withConfig(String, String)
      • withConfig

        @QueryParam("config.<key>")
        public SFTPEnvironment withConfig​(String key,
                                          String value)
        Stores a configuration option to use. This method will add not clear any previously set options, but only add new ones.
        Parameters:
        key - The configuration key.
        value - The configuration value.
        Returns:
        This object.
        Throws:
        NullPointerException - if the given key or value is null.
        See Also:
        withConfig(Properties)
      • withAppendedConfig

        @QueryParam("appendedConfig.<key>")
        public SFTPEnvironment withAppendedConfig​(String key,
                                                  String value)
        Stores a configuration option to use. Unlike withConfig(String, String), configuration options set using this method will be appended to existing configuration options instead of overwriting them. For instance, this method can be used to add support for ssh-rsa keys as follows:
        
         // JSch way:
         // session.setConfig("server_host_key", session.getConfig("server_host_key") + ",ssh-rsa");
         // session.setConfig("PubkeyAcceptedAlgorithms", session.getConfig("PubkeyAcceptedAlgorithms") + ",ssh-rsa");
        
         // sftp-fs way:
         SFTPEnvironment env = new SFTPEnvironment()
                 ...
                 .withAppendedConfig("server_host_key", "ssh-rsa")
                 .withAppendedConfig("PubkeyAcceptedAlgorithms", "ssh-rsa");
         

        This method will use a comma to append configuration options. If this does not fit your needs, use withAppendedConfig(String, String, BinaryOperator) with a custom appender.

        Parameters:
        key - The configuration key.
        value - The configuration value.
        Returns:
        This object.
        Throws:
        NullPointerException - If the given key or value is null.
        Since:
        3.2
      • withAppendedConfig

        public SFTPEnvironment withAppendedConfig​(String key,
                                                  String value,
                                                  BinaryOperator<String> appender)
        Stores a configuration option to use. This is a more generalized version of withAppendedConfig(String, String) that allows non-default combining of existing and new configuration options.
        Parameters:
        key - The configuration key.
        value - The configuration value.
        appender - A function that takes the previously configured option and the new option and returns a combined configuration option.
        Returns:
        This object.
        Throws:
        NullPointerException - If the given key, value or appender function is null.
        Since:
        3.2
      • withSocketFactory

        public SFTPEnvironment withSocketFactory​(SocketFactory factory)
        Stores the socket factory to use.
        Parameters:
        factory - The socket factory to use.
        Returns:
        This object.
      • withClientVersion

        @QueryParam("clientVersion")
        public SFTPEnvironment withClientVersion​(String version)
        Stores the client version to use.
        Parameters:
        version - The client version.
        Returns:
        This object.
      • withHostKeyAlias

        @QueryParam("hostKeyAlias")
        public SFTPEnvironment withHostKeyAlias​(String alias)
        Stores the host key alias to use.
        Parameters:
        alias - The host key alias.
        Returns:
        This object.
      • withServerAliveInterval

        @QueryParam("serverAliveInterval")
        public SFTPEnvironment withServerAliveInterval​(int interval)
        Stores the server alive interval to use.
        Parameters:
        interval - The server alive interval in milliseconds.
        Returns:
        This object.
      • withServerAliveCountMax

        @QueryParam("serverAliveCountMax")
        public SFTPEnvironment withServerAliveCountMax​(int count)
        Stores the maximum number of server alive messages that can be sent without any reply before disconnecting.
        Parameters:
        count - The maximum number of server alive messages.
        Returns:
        This object.
      • withIdentityRepository

        public SFTPEnvironment withIdentityRepository​(IdentityRepository repository)
        Stores the identity repository to use.
        Parameters:
        repository - The identity repository to use.
        Returns:
        This object.
      • withHostKeyRepository

        public SFTPEnvironment withHostKeyRepository​(HostKeyRepository repository)
        Stores the host key repository to use.
        Parameters:
        repository - The host key repository to use.
        Returns:
        This object.
      • withConfigRepository

        public SFTPEnvironment withConfigRepository​(ConfigRepository repository)
        Stores the config repository to use.
        Parameters:
        repository - The config repository to use.
        Returns:
        This object.
        Since:
        3.1
      • withAgentForwarding

        @QueryParam("agentForwarding")
        public SFTPEnvironment withAgentForwarding​(boolean agentForwarding)
        Stores whether or not agent forwarding should be enabled.
        Parameters:
        agentForwarding - true to enable strict agent forwarding, or false to disable it.
        Returns:
        This object.
      • withFilenameEncoding

        @QueryParam("filenameEncoding")
        public SFTPEnvironment withFilenameEncoding​(Charset encoding)
        Stores the filename encoding to use.
        Parameters:
        encoding - The filename encoding to use.
        Returns:
        This object.
      • withDefaultDirectory

        @QueryParam("defaultDir")
        public SFTPEnvironment withDefaultDirectory​(String pathname)
        Stores the default directory to use. If it exists, this will be the directory that relative paths are resolved to.
        Parameters:
        pathname - The default directory to use.
        Returns:
        This object.
      • withPoolConfig

        @QueryParam("poolConfig.maxWaitTime") @QueryParam("poolConfig.maxIdleTime") @QueryParam("poolConfig.initialSize") @QueryParam("poolConfig.maxSize")
        public SFTPEnvironment withPoolConfig​(SFTPPoolConfig poolConfig)
        Stores the pool config to use.

        The maximum pool size influences the number of concurrent threads that can access an SFTP file system.
        If the maximum wait time is negative, SFTP file systems wait indefinitely until a client connection is available. This is the default setting if no pool config is defined.

        Parameters:
        poolConfig - The pool config to use.
        Returns:
        This object.
        Since:
        3.0
      • withFileSystemExceptionFactory

        public SFTPEnvironment withFileSystemExceptionFactory​(FileSystemExceptionFactory factory)
        Stores the file system exception factory to use.
        Parameters:
        factory - The file system exception factory to use.
        Returns:
        This object.
      • setDefault

        public static void setDefault​(SFTPEnvironment defaultEnvironment)
        Sets the default SFTP environment. This is used in SFTPFileSystemProvider.getPath(URI) when a file system needs to be created, since no environment can be passed. This way, certain settings like pool configuration can still be applied.
        Parameters:
        defaultEnvironment - The default SFTP environment. Use null to reset it to an empty environment.
        Since:
        3.3