Class FTPEnvironment
- java.lang.Object
-
- com.github.robtimus.filesystems.ftp.FTPEnvironment
-
- Direct Known Subclasses:
FTPSEnvironment
public class FTPEnvironment extends Object implements Map<String,Object>
A utility class to set up environments that can be used in theFileSystemProvider.newFileSystem(URI, Map)andFileSystemProvider.newFileSystem(Path, Map)methods ofFTPFileSystemProvider.- Author:
- Rob Spoor
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceFTPEnvironment.QueryParamIndicates which query parameters can be used to define environment values.static interfaceFTPEnvironment.QueryParamsA container forFTPEnvironment.QueryParamannotations.
-
Constructor Summary
Constructors Constructor Description FTPEnvironment()Creates a new FTP environment.FTPEnvironment(Map<String,Object> map)Creates a new FTP environment.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidclear()booleancontainsKey(Object key)booleancontainsValue(Object value)static FTPEnvironmentcopy(Map<String,?> env)Copies a map to create a newFTPEnvironmentinstance.Set<Map.Entry<String,Object>>entrySet()booleanequals(Object o)Objectget(Object key)inthashCode()booleanisEmpty()Set<String>keySet()Objectput(String key, Object value)voidputAll(Map<? extends String,? extends Object> m)Objectremove(Object key)static voidsetDefault(FTPEnvironment defaultEnvironment)Sets the default FTP environment.intsize()StringtoString()Collection<Object>values()FTPEnvironmentwithActiveExternalIPAddress(String ipAddress)Stores the external IP address in active mode.FTPEnvironmentwithActivePortRange(int minPort, int maxPort)Stores the client side port range in active mode.FTPEnvironmentwithAutodetectEncoding(boolean autodetect)Stores whether or not automatic server encoding detection should be enabled.FTPEnvironmentwithBufferSize(int bufferSize)Stores the buffer size to use.FTPEnvironmentwithCharset(Charset charset)Stores the charset to use.FTPEnvironmentwithClientConfig(FTPClientConfig clientConfig)Stores the FTP client config to use.FTPEnvironmentwithConnectionMode(ConnectionMode connectionMode)Stores the connection mode to use.FTPEnvironmentwithConnectTimeout(int timeout)Stores the connection timeout to use.FTPEnvironmentwithControlEncoding(String encoding)Stores the character encoding to be used by the FTP control connection.FTPEnvironmentwithControlKeepAliveReplyTimeout(int timeout)Deprecated.UsewithControlKeepAliveReplyTimeout(Duration)instead.FTPEnvironmentwithControlKeepAliveReplyTimeout(Duration timeout)Stores how long to wait for control keep-alive message replies.FTPEnvironmentwithControlKeepAliveTimeout(long timeout)Deprecated.UsewithControlKeepAliveTimeout(Duration)instead.FTPEnvironmentwithControlKeepAliveTimeout(Duration timeout)Stores the time to wait between sending control connection keep-alive messages when processing file upload or download.FTPEnvironmentwithCredentials(String username, char[] password)Stores the credentials to use.FTPEnvironmentwithCredentials(String username, char[] password, String account)Stores the credentials to use.FTPEnvironmentwithDataTimeout(int timeout)Deprecated.UsewithDataTimeout(Duration)instead.FTPEnvironmentwithDataTimeout(Duration timeout)Stores the timeout to use when reading from data connections.FTPEnvironmentwithDefaultDirectory(String pathname)Stores the default directory to use.FTPEnvironmentwithFileSystemExceptionFactory(FileSystemExceptionFactory factory)Stores the file system exception factory to use.FTPEnvironmentwithFTPFileStrategyFactory(FTPFileStrategyFactory factory)Stores the FTP file strategy factory to use.FTPEnvironmentwithIpAddressFromPasvResponse(boolean usingIpAddressFromPasvResponse)Sets whether or not the IP address from the server's response should be used.FTPEnvironmentwithKeepAlive(boolean keepAlive)Stores whether or notSO_KEEPALIVEshould be enabled.FTPEnvironmentwithListHiddenFiles(boolean listHiddenFiles)Stores whether or not to list hidden files.FTPEnvironmentwithLocalAddress(InetAddress localAddr, int localPort)Stores the local address to use.FTPEnvironmentwithParserFactory(FTPFileEntryParserFactory parserFactory)Stores the factory used for parser creation.FTPEnvironmentwithPassiveLocalIPAddress(String ipAddress)Stores the local IP address to use in passive mode.FTPEnvironmentwithPassiveNatWorkaroundStrategy(FTPClient.HostnameResolver resolver)Stores the workaround strategy to replace the PASV mode reply addresses.FTPEnvironmentwithPoolConfig(FTPPoolConfig poolConfig)Stores the pool config to use.FTPEnvironmentwithProxy(Proxy proxy)Stores the proxy to use.FTPEnvironmentwithReceiveBufferSize(int size)Stores the socket receive buffer size to use.FTPEnvironmentwithReceiveDataSocketBufferSize(int bufferSize)Stores the value to use for the data socketSO_RCVBUFoption.FTPEnvironmentwithRemoteVerificationEnabled(boolean enabled)Stores whether or not verification that the remote host taking part of a data connection is the same as the host to which the control connection is attached should be enabled.FTPEnvironmentwithReportActiveExternalIPAddress(String ipAddress)Stores the external IP address to report in EPRT/PORT commands in active mode.FTPEnvironmentwithSendBufferSize(int size)Stores the socket send buffer size to use.FTPEnvironmentwithSendDataSocketBufferSize(int bufferSizr)Stores the value to use for the data socketSO_SNDBUFoption.FTPEnvironmentwithServerSocketFactory(ServerSocketFactory factory)Stores the server socket factory to use.FTPEnvironmentwithSocketFactory(SocketFactory factory)Stores the socket factory to use.FTPEnvironmentwithSoLinger(boolean on, int linger)Stores whether or notSO_LINGERshould be enabled, and if so, the linger time.FTPEnvironmentwithSoTimeout(int timeout)Stores the socket timeout.FTPEnvironmentwithStrictMultilineParsing(boolean strictMultilineParsing)Stores whether or not strict multiline parsing should be enabled, as per RFC 959, section 4.2.FTPEnvironmentwithTcpNoDelay(boolean on)Stores whether or not the Nagle's algorithm (TCP_NODELAY) should be enabled.FTPEnvironmentwithUseEPSVwithIPv4(boolean selected)Stores whether or not to use EPSV with IPv4.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
-
-
-
Method Detail
-
withLocalAddress
@QueryParam("localAddr") @QueryParam("localPort") public FTPEnvironment withLocalAddress(InetAddress localAddr, int localPort)
Stores the local address to use.- Parameters:
localAddr- The local address to use.localPort- The local port to use.- Returns:
- This object.
- See Also:
Socket.bind(SocketAddress),InetSocketAddress(InetAddress, int)
-
withCredentials
public FTPEnvironment withCredentials(String username, char[] password)
Stores the credentials to use.- Parameters:
username- The username to use.password- The password to use.- Returns:
- This object.
-
withCredentials
@QueryParam("account") public FTPEnvironment withCredentials(String username, char[] password, String account)
Stores the credentials to use.- Parameters:
username- The username to use.password- The password to use.account- The account to use.- Returns:
- This object.
-
withSoTimeout
@QueryParam("soTimeout") public FTPEnvironment withSoTimeout(int timeout)
Stores the socket timeout.- Parameters:
timeout- The socket timeout in milliseconds.- Returns:
- This object.
- See Also:
Socket.setSoTimeout(int)
-
withSendBufferSize
@QueryParam("sendBufferSize") public FTPEnvironment withSendBufferSize(int size)
Stores the socket send buffer size to use.- Parameters:
size- The size of the buffer in bytes.- Returns:
- This object.
- See Also:
Socket.setSendBufferSize(int)
-
withReceiveBufferSize
@QueryParam("receiveBufferSize") public FTPEnvironment withReceiveBufferSize(int size)
Stores the socket receive buffer size to use.- Parameters:
size- The size of the buffer in bytes.- Returns:
- This object.
- See Also:
Socket.setReceiveBufferSize(int)
-
withTcpNoDelay
@QueryParam("tcpNoDelay") public FTPEnvironment withTcpNoDelay(boolean on)
Stores whether or not the Nagle's algorithm (TCP_NODELAY) should be enabled.- Parameters:
on-trueif Nagle's algorithm should be enabled, orfalseotherwise.- Returns:
- This object.
- See Also:
Socket.setTcpNoDelay(boolean)
-
withKeepAlive
@QueryParam("keepAlive") public FTPEnvironment withKeepAlive(boolean keepAlive)
Stores whether or notSO_KEEPALIVEshould be enabled.- Parameters:
keepAlive-trueif keep-alive should be enabled, orfalseotherwise.- Returns:
- This object.
- See Also:
Socket.setKeepAlive(boolean)
-
withSoLinger
@QueryParam("soLinger.on") @QueryParam("soLinger.val") public FTPEnvironment withSoLinger(boolean on, int linger)
Stores whether or notSO_LINGERshould be enabled, and if so, the linger time.- Parameters:
on-trueifSO_LINGERshould be enabled, orfalseotherwise.linger- The linger time in seconds, ifonistrue.- Returns:
- This object.
- See Also:
Socket.setSoLinger(boolean, int)
-
withSocketFactory
public FTPEnvironment withSocketFactory(SocketFactory factory)
Stores the socket factory to use.- Parameters:
factory- The socket factory to use.- Returns:
- This object.
-
withServerSocketFactory
public FTPEnvironment withServerSocketFactory(ServerSocketFactory factory)
Stores the server socket factory to use.- Parameters:
factory- The server socket factory to use.- Returns:
- This object.
-
withConnectTimeout
@QueryParam("connectTimeout") public FTPEnvironment withConnectTimeout(int timeout)
Stores the connection timeout to use.- Parameters:
timeout- The connection timeout in milliseconds.- Returns:
- This object.
- See Also:
Socket.connect(SocketAddress, int)
-
withProxy
public FTPEnvironment withProxy(Proxy proxy)
Stores the proxy to use.- Parameters:
proxy- The proxy to use.- Returns:
- This object.
-
withCharset
@QueryParam("charset") public FTPEnvironment withCharset(Charset charset)
Stores the charset to use.- Parameters:
charset- The charset to use.- Returns:
- This object.
-
withControlEncoding
@QueryParam("controlEncoding") public FTPEnvironment withControlEncoding(String encoding)
Stores the character encoding to be used by the FTP control connection. Some FTP servers require that commands be issued in a non-ASCII encoding like UTF-8 so that filenames with multi-byte character representations (e.g, Big 8) can be specified.- Parameters:
encoding- The character encoding to use.- Returns:
- This object.
-
withStrictMultilineParsing
@QueryParam("strictMultilineParsing") public FTPEnvironment withStrictMultilineParsing(boolean strictMultilineParsing)
Stores whether or not strict multiline parsing should be enabled, as per RFC 959, section 4.2.- Parameters:
strictMultilineParsing-trueto enable strict multiline parsing, orfalseto disable it.- Returns:
- This object.
- Since:
- 2.1
-
withDataTimeout
@Deprecated public FTPEnvironment withDataTimeout(int timeout)
Deprecated.UsewithDataTimeout(Duration)instead.Stores the timeout in milliseconds to use when reading from data connections.- Parameters:
timeout- The timeout in milliseconds that is used when opening data connection sockets.- Returns:
- This object.
-
withDataTimeout
@QueryParam("dataTimeout") public FTPEnvironment withDataTimeout(Duration timeout)
Stores the timeout to use when reading from data connections.- Parameters:
timeout- The timeout in milliseconds that is used when opening data connection sockets.- Returns:
- This object.
- Since:
- 3.1
-
withParserFactory
public FTPEnvironment withParserFactory(FTPFileEntryParserFactory parserFactory)
Stores the factory used for parser creation.- Parameters:
parserFactory- The factory object used to createFTPFileEntryParsers- Returns:
- This object.
-
withIpAddressFromPasvResponse
@QueryParam("ipAddressFromPasvResponse") public FTPEnvironment withIpAddressFromPasvResponse(boolean usingIpAddressFromPasvResponse)
Sets whether or not the IP address from the server's response should be used. Before version 3.1 (and version 3.9.0 of Apache Commons Net), this has always been the case. Beginning with version 3.1, that IP address will be silently ignored, and replaced with the remote IP address of the control connection, unless this configuration option is given, which restores the old behavior. To enable this by default, use the system propertyFTPClient.FTP_IP_ADDRESS_FROM_PASV_RESPONSE.- Parameters:
usingIpAddressFromPasvResponse-trueif the IP address from the server's response should be used, orfalseto ignore that IP address.- Returns:
- This object.
- Since:
- 3.1
-
withRemoteVerificationEnabled
@QueryParam("remoteVerificationEnabled") public FTPEnvironment withRemoteVerificationEnabled(boolean enabled)
Stores whether or not verification that the remote host taking part of a data connection is the same as the host to which the control connection is attached should be enabled.- Parameters:
enabled-trueto enable verification, orfalseto disable verification.- Returns:
- This object.
-
withDefaultDirectory
@QueryParam("defaultDir") public FTPEnvironment 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.
-
withConnectionMode
@QueryParam("connectionMode") public FTPEnvironment withConnectionMode(ConnectionMode connectionMode)
Stores the connection mode to use. If the connection mode is not set, it will default toConnectionMode.ACTIVE.- Parameters:
connectionMode- The connection mode to use.- Returns:
- This object.
-
withActivePortRange
@QueryParam("activePortRange.min") @QueryParam("activePortRange.max") public FTPEnvironment withActivePortRange(int minPort, int maxPort)
Stores the client side port range in active mode.- Parameters:
minPort- The lowest available port (inclusive).maxPort- The highest available port (inclusive).- Returns:
- This object.
-
withActiveExternalIPAddress
@QueryParam("activeExternalIPAddress") public FTPEnvironment withActiveExternalIPAddress(String ipAddress)
Stores the external IP address in active mode. Useful when there are multiple network cards.- Parameters:
ipAddress- The external IP address of this machine.- Returns:
- This object.
-
withPassiveLocalIPAddress
@QueryParam("passiveLocalIPAddress") public FTPEnvironment withPassiveLocalIPAddress(String ipAddress)
Stores the local IP address to use in passive mode. Useful when there are multiple network cards.- Parameters:
ipAddress- The local IP address of this machine.- Returns:
- This object.
-
withReportActiveExternalIPAddress
@QueryParam("reportActiveExternalIPAddress") public FTPEnvironment withReportActiveExternalIPAddress(String ipAddress)
Stores the external IP address to report in EPRT/PORT commands in active mode. Useful when there are multiple network cards.- Parameters:
ipAddress- The external IP address of this machine.- Returns:
- This object.
-
withBufferSize
@QueryParam("bufferSize") public FTPEnvironment withBufferSize(int bufferSize)
Stores the buffer size to use.- Parameters:
bufferSize- The buffer size to use.- Returns:
- This object.
-
withSendDataSocketBufferSize
@QueryParam("sendDataSocketBufferSize") public FTPEnvironment withSendDataSocketBufferSize(int bufferSizr)
Stores the value to use for the data socketSO_SNDBUFoption.- Parameters:
bufferSizr- The size of the buffer.- Returns:
- This object.
-
withReceiveDataSocketBufferSize
@QueryParam("receiveDataSocketBufferSize") public FTPEnvironment withReceiveDataSocketBufferSize(int bufferSize)
Stores the value to use for the data socketSO_RCVBUFoption.- Parameters:
bufferSize- The size of the buffer.- Returns:
- This object.
-
withClientConfig
public FTPEnvironment withClientConfig(FTPClientConfig clientConfig)
Stores the FTP client config to use.- Parameters:
clientConfig- The client config to use.- Returns:
- This object.
-
withUseEPSVwithIPv4
@QueryParam("useEPSVwithIPv4") public FTPEnvironment withUseEPSVwithIPv4(boolean selected)
Stores whether or not to use EPSV with IPv4. Might be worth enabling in some circumstances.For example, when using IPv4 with NAT it may work with some rare configurations. E.g. if FTP server has a static PASV address (external network) and the client is coming from another internal network. In that case the data connection after PASV command would fail, while EPSV would make the client succeed by taking just the port.
- Parameters:
selected- The flag to use.- Returns:
- This object.
-
withControlKeepAliveTimeout
@Deprecated public FTPEnvironment withControlKeepAliveTimeout(long timeout)
Deprecated.UsewithControlKeepAliveTimeout(Duration)instead.Stores the time to wait between sending control connection keep-alive messages when processing file upload or download.- Parameters:
timeout- The keep-alive timeout to use, in milliseconds.- Returns:
- This object.
-
withControlKeepAliveTimeout
@QueryParam("controlKeepAliveTimeout") public FTPEnvironment withControlKeepAliveTimeout(Duration timeout)
Stores the time to wait between sending control connection keep-alive messages when processing file upload or download.- Parameters:
timeout- The keep-alive timeout to use.- Returns:
- This object.
- Since:
- 3.1
-
withControlKeepAliveReplyTimeout
@Deprecated public FTPEnvironment withControlKeepAliveReplyTimeout(int timeout)
Deprecated.UsewithControlKeepAliveReplyTimeout(Duration)instead.Stores how long to wait for control keep-alive message replies.- Parameters:
timeout- The keep-alive reply timeout to use, in milliseconds.- Returns:
- This object.
-
withControlKeepAliveReplyTimeout
@QueryParam("controlKeepAliveReplyTimeout") public FTPEnvironment withControlKeepAliveReplyTimeout(Duration timeout)
Stores how long to wait for control keep-alive message replies.- Parameters:
timeout- The keep-alive reply timeout to use.- Returns:
- This object.
- Since:
- 3.1
-
withPassiveNatWorkaroundStrategy
public FTPEnvironment withPassiveNatWorkaroundStrategy(FTPClient.HostnameResolver resolver)
Stores the workaround strategy to replace the PASV mode reply addresses. This gets around the problem that some NAT boxes may change the reply. The default implementation isFTPClient.NatServerResolverImpl, i.e. site-local replies are replaced.- Parameters:
resolver- The workaround strategy to replace internal IP's in passive mode, ornullto disable the workaround (i.e. use PASV mode reply address.)- Returns:
- This object.
- Since:
- 1.1
-
withAutodetectEncoding
@QueryParam("autodetectEncoding") public FTPEnvironment withAutodetectEncoding(boolean autodetect)
Stores whether or not automatic server encoding detection should be enabled. Note that only UTF-8 is supported.- Parameters:
autodetect-trueto enable automatic server encoding detection, orfalseto disable it.- Returns:
- This object.
-
withListHiddenFiles
@QueryParam("listHiddenFiles") public FTPEnvironment withListHiddenFiles(boolean listHiddenFiles)
Stores whether or not to list hidden files. If this flag is not set, it will default totrue.Note that if this flag is set to
false, the current directory will (most likely) not be returned when listing directories. That means thatStandardFTPFileStrategyFactory.UNIXwill not work correctly.Ideally, only set this flag (to
false) if the FTP server does not support the-aoption forLISTcommands.- Parameters:
listHiddenFiles-trueto list hidden files, orfalseto omit them.- Returns:
- This object.
- Since:
- 2.0
-
withPoolConfig
@QueryParam("poolConfig.maxWaitTime") @QueryParam("poolConfig.maxIdleTime") @QueryParam("poolConfig.initialSize") @QueryParam("poolConfig.maxSize") public FTPEnvironment withPoolConfig(FTPPoolConfig poolConfig)
Stores the pool config to use.The maximum pool size influences the number of concurrent threads that can access an FTP file system.
If the maximum wait time is negative, FTP 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 FTPEnvironment withFileSystemExceptionFactory(FileSystemExceptionFactory factory)
Stores the file system exception factory to use.- Parameters:
factory- The file system exception factory to use.- Returns:
- This object.
-
withFTPFileStrategyFactory
public FTPEnvironment withFTPFileStrategyFactory(FTPFileStrategyFactory factory)
Stores the FTP file strategy factory to use. If the FTP file strategy factory is not set, it will default toStandardFTPFileStrategyFactory.AUTO_DETECT.- Parameters:
factory- The FTP file strategy factory to use.- Returns:
- This object.
-
containsKey
public boolean containsKey(Object key)
- Specified by:
containsKeyin interfaceMap<String,Object>
-
containsValue
public boolean containsValue(Object value)
- Specified by:
containsValuein interfaceMap<String,Object>
-
equals
public boolean equals(Object o)
-
hashCode
public int hashCode()
-
copy
public static FTPEnvironment copy(Map<String,?> env)
Copies a map to create a newFTPEnvironmentinstance. If the given map is an instance ofFTPSEnvironment, this method will return a newFTPSEnvironmentinstance.- Parameters:
env- The map to copy. It can be anFTPEnvironmentinstance, but does not have to be.- Returns:
- A new
FTPEnvironmentinstance that is a copy of the given map. - Since:
- 3.0
-
setDefault
public static void setDefault(FTPEnvironment defaultEnvironment)
Sets the default FTP environment. This is used inFTPFileSystemProvider.getPath(URI)when a file system needs to be created, since no environment can be passed. This way, certain settings likepool configurationcan still be applied.- Parameters:
defaultEnvironment- The default FTP environment. Usenullto reset it to an empty environment.- Since:
- 3.2
-
-