Class FTPEnvironment

    • Constructor Detail

      • FTPEnvironment

        public FTPEnvironment()
        Creates a new FTP environment.
      • FTPEnvironment

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

      • 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.
      • withTcpNoDelay

        @QueryParam("tcpNoDelay")
        public FTPEnvironment withTcpNoDelay​(boolean on)
        Stores whether or not the Nagle's algorithm (TCP_NODELAY) should be enabled.
        Parameters:
        on - true if Nagle's algorithm should be enabled, or false otherwise.
        Returns:
        This object.
        See Also:
        Socket.setTcpNoDelay(boolean)
      • withKeepAlive

        @QueryParam("keepAlive")
        public FTPEnvironment withKeepAlive​(boolean keepAlive)
        Stores whether or not SO_KEEPALIVE should be enabled.
        Parameters:
        keepAlive - true if keep-alive should be enabled, or false otherwise.
        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 not SO_LINGER should be enabled, and if so, the linger time.
        Parameters:
        on - true if SO_LINGER should be enabled, or false otherwise.
        linger - The linger time in seconds, if on is true.
        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.
      • 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 - true to enable strict multiline parsing, or false to disable it.
        Returns:
        This object.
        Since:
        2.1
      • withDataTimeout

        @Deprecated
        public FTPEnvironment withDataTimeout​(int timeout)
        Deprecated.
        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
      • 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 property FTPClient.FTP_IP_ADDRESS_FROM_PASV_RESPONSE.
        Parameters:
        usingIpAddressFromPasvResponse - true if the IP address from the server's response should be used, or false to 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 - true to enable verification, or false to 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 to ConnectionMode.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 socket SO_SNDBUF option.
        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 socket SO_RCVBUF option.
        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.
        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)
        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 is FTPClient.NatServerResolverImpl, i.e. site-local replies are replaced.
        Parameters:
        resolver - The workaround strategy to replace internal IP's in passive mode, or null to 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 - true to enable automatic server encoding detection, or false to 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 to true.

        Note that if this flag is set to false, the current directory will (most likely) not be returned when listing directories. That means that StandardFTPFileStrategyFactory.UNIX will not work correctly.

        Ideally, only set this flag (to false) if the FTP server does not support the -a option for LIST commands.

        Parameters:
        listHiddenFiles - true to list hidden files, or false to 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.
      • setDefault

        public static void setDefault​(FTPEnvironment defaultEnvironment)
        Sets the default FTP environment. This is used in FTPFileSystemProvider.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 FTP environment. Use null to reset it to an empty environment.
        Since:
        3.2