public class SFTPEnvironment extends Object implements Map<String,Object>
FileSystemProvider.newFileSystem(URI, Map)
and
FileSystemProvider.newFileSystem(Path, Map)
methods of SFTPFileSystemProvider
.Modifier and Type | Class and Description |
---|---|
static interface |
SFTPEnvironment.QueryParam
Indicates which query parameters can be used to define environment values.
|
static interface |
SFTPEnvironment.QueryParams
A container for
SFTPEnvironment.QueryParam annotations. |
Constructor and Description |
---|
SFTPEnvironment()
Creates a new SFTP environment.
|
SFTPEnvironment(Map<String,Object> map)
Creates a new SFTP environment.
|
Modifier and Type | Method and Description |
---|---|
void |
clear() |
boolean |
containsKey(Object key) |
boolean |
containsValue(Object value) |
static SFTPEnvironment |
copy(Map<String,?> env)
Copies a map to create a new
SFTPEnvironment instance. |
Set<Map.Entry<String,Object>> |
entrySet() |
boolean |
equals(Object o) |
Object |
get(Object key) |
int |
hashCode() |
boolean |
isEmpty() |
Set<String> |
keySet() |
Object |
put(String key,
Object value) |
void |
putAll(Map<? extends String,? extends Object> m) |
Object |
remove(Object key) |
static void |
setDefault(SFTPEnvironment defaultEnvironment)
Sets the default SFTP environment.
|
int |
size() |
String |
toString() |
Collection<Object> |
values() |
SFTPEnvironment |
withAgentForwarding(boolean agentForwarding)
Stores whether or not agent forwarding should be enabled.
|
SFTPEnvironment |
withAppendedConfig(String key,
String value)
Stores a configuration option to use.
|
SFTPEnvironment |
withAppendedConfig(String key,
String value,
BinaryOperator<String> appender)
Stores a configuration option to use.
|
SFTPEnvironment |
withClientVersion(String version)
Stores the client version to use.
|
SFTPEnvironment |
withConfig(Properties config)
Stores configuration options to use.
|
SFTPEnvironment |
withConfig(String key,
String value)
Stores a configuration option to use.
|
SFTPEnvironment |
withConfigRepository(ConfigRepository repository)
Stores the config repository to use.
|
SFTPEnvironment |
withConnectTimeout(int timeout)
Stores the connection timeout to use.
|
SFTPEnvironment |
withDefaultDirectory(String pathname)
Stores the default directory to use.
|
SFTPEnvironment |
withFilenameEncoding(Charset encoding)
Stores the filename encoding to use.
|
SFTPEnvironment |
withFileSystemExceptionFactory(FileSystemExceptionFactory factory)
Stores the file system exception factory to use.
|
SFTPEnvironment |
withHostKeyAlias(String alias)
Stores the host key alias to use.
|
SFTPEnvironment |
withHostKeyRepository(HostKeyRepository repository)
Stores the host key repository to use.
|
SFTPEnvironment |
withIdentities(Collection<Identity> identities)
Stores several identity to use.
|
SFTPEnvironment |
withIdentities(Identity... identities)
Stores several identity to use.
|
SFTPEnvironment |
withIdentity(Identity identity)
Stores an identity to use.
|
SFTPEnvironment |
withIdentityRepository(IdentityRepository repository)
Stores the identity repository to use.
|
SFTPEnvironment |
withKnownHosts(File knownHosts)
Stores the known hosts file to use.
|
SFTPEnvironment |
withPassword(char[] password)
Stores the password to use.
|
SFTPEnvironment |
withPoolConfig(SFTPPoolConfig poolConfig)
Stores the pool config to use.
|
SFTPEnvironment |
withProxy(Proxy proxy)
Stores the proxy to use.
|
SFTPEnvironment |
withServerAliveCountMax(int count)
Stores the maximum number of server alive messages that can be sent without any reply before disconnecting.
|
SFTPEnvironment |
withServerAliveInterval(int interval)
Stores the server alive interval to use.
|
SFTPEnvironment |
withSocketFactory(SocketFactory factory)
Stores the socket factory to use.
|
SFTPEnvironment |
withTimeout(int timeout)
Stores the timeout.
|
SFTPEnvironment |
withUserInfo(UserInfo userInfo)
Stores the user info to use.
|
SFTPEnvironment |
withUsername(String username)
Stores the username to use.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
public SFTPEnvironment withUsername(String username)
username
- The username to use.@SFTPEnvironment.QueryParam(value="connectTimeout") public SFTPEnvironment withConnectTimeout(int timeout)
timeout
- The connection timeout in milliseconds.public SFTPEnvironment withProxy(Proxy proxy)
proxy
- The proxy to use.public SFTPEnvironment withUserInfo(UserInfo userInfo)
userInfo
- The user info to use.public SFTPEnvironment withPassword(char[] password)
password
- The password to use.public SFTPEnvironment withConfig(Properties config)
config
- The configuration options to use.NullPointerException
- if the given properties object is null
.withConfig(String, String)
@SFTPEnvironment.QueryParam(value="config.<key>") public SFTPEnvironment withConfig(String key, String value)
key
- The configuration key.value
- The configuration value.NullPointerException
- if the given key or value is null
.withConfig(Properties)
@SFTPEnvironment.QueryParam(value="appendedConfig.<key>") public SFTPEnvironment withAppendedConfig(String key, String value)
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.
key
- The configuration key.value
- The configuration value.NullPointerException
- If the given key or value is null
.public SFTPEnvironment withAppendedConfig(String key, String value, BinaryOperator<String> appender)
withAppendedConfig(String, String)
that allows
non-default combining of existing and new configuration options.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.NullPointerException
- If the given key, value or appender function is null
.public SFTPEnvironment withSocketFactory(SocketFactory factory)
factory
- The socket factory to use.@SFTPEnvironment.QueryParam(value="timeout") public SFTPEnvironment withTimeout(int timeout)
timeout
- The timeout in milliseconds.Socket.setSoTimeout(int)
@SFTPEnvironment.QueryParam(value="clientVersion") public SFTPEnvironment withClientVersion(String version)
version
- The client version.@SFTPEnvironment.QueryParam(value="hostKeyAlias") public SFTPEnvironment withHostKeyAlias(String alias)
alias
- The host key alias.@SFTPEnvironment.QueryParam(value="serverAliveInterval") public SFTPEnvironment withServerAliveInterval(int interval)
interval
- The server alive interval in milliseconds.@SFTPEnvironment.QueryParam(value="serverAliveCountMax") public SFTPEnvironment withServerAliveCountMax(int count)
count
- The maximum number of server alive messages.public SFTPEnvironment withIdentityRepository(IdentityRepository repository)
repository
- The identity repository to use.public SFTPEnvironment withIdentity(Identity identity)
identity
- The identity to use.NullPointerException
- If the given identity is null
.withIdentities(Identity...)
,
withIdentities(Collection)
public SFTPEnvironment withIdentities(Identity... identities)
identities
- The identities to use.NullPointerException
- If any of the given identity is null
.withIdentity(Identity)
,
withIdentities(Collection)
public SFTPEnvironment withIdentities(Collection<Identity> identities)
identities
- The identities to use.NullPointerException
- If any of the given identity is null
.withIdentity(Identity)
,
withIdentities(Identity...)
public SFTPEnvironment withHostKeyRepository(HostKeyRepository repository)
repository
- The host key repository to use.public SFTPEnvironment withKnownHosts(File knownHosts)
HostKeyRepository
is set with a non-null
value.knownHosts
- The known hosts file to use.NullPointerException
- If the given file is null
.withHostKeyRepository(HostKeyRepository)
public SFTPEnvironment withConfigRepository(ConfigRepository repository)
repository
- The config repository to use.@SFTPEnvironment.QueryParam(value="agentForwarding") public SFTPEnvironment withAgentForwarding(boolean agentForwarding)
agentForwarding
- true
to enable strict agent forwarding, or false
to disable it.@SFTPEnvironment.QueryParam(value="filenameEncoding") public SFTPEnvironment withFilenameEncoding(Charset encoding)
encoding
- The filename encoding to use.@SFTPEnvironment.QueryParam(value="defaultDir") public SFTPEnvironment withDefaultDirectory(String pathname)
pathname
- The default directory to use.@SFTPEnvironment.QueryParam(value="poolConfig.maxWaitTime") @SFTPEnvironment.QueryParam(value="poolConfig.maxIdleTime") @SFTPEnvironment.QueryParam(value="poolConfig.initialSize") @SFTPEnvironment.QueryParam(value="poolConfig.maxSize") public SFTPEnvironment withPoolConfig(SFTPPoolConfig poolConfig)
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.
poolConfig
- The pool config to use.public SFTPEnvironment withFileSystemExceptionFactory(FileSystemExceptionFactory factory)
factory
- The file system exception factory to use.public boolean containsKey(Object key)
containsKey
in interface Map<String,Object>
public boolean containsValue(Object value)
containsValue
in interface Map<String,Object>
public boolean equals(Object o)
public int hashCode()
public static SFTPEnvironment copy(Map<String,?> env)
SFTPEnvironment
instance.env
- The map to copy. It can be an SFTPEnvironment
instance, but does not have to be.SFTPEnvironment
instance that is a copy of the given map.public static void setDefault(SFTPEnvironment defaultEnvironment)
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.defaultEnvironment
- The default SFTP environment. Use null
to reset it to an empty environment.Copyright © 2016–2023. All rights reserved.