Repository navigation
GH-6485: Add proxy support to the FTP session factories - #11535
Merged
Merged
Conversation
Fixes: spring-projects#6485 An FTP (or FTPS) server behind a proxy could only be reached with the proxy system properties of the JVM, which affect every connection of the application, or with a custom session factory. * Add the `proxy` property to the `AbstractFtpSessionFactory`, which applies a `java.net.Proxy` (SOCKS or HTTP) to the `FTPClient`, so it is used for the control connection and for the data connections * Require the passive client mode when a proxy is used, because the server cannot connect back to the client through a proxy * Add the `FtpHttpProxySessionFactory`, based on the `FTPHTTPClient`, for an HTTP proxy that requires credentials * Test both against the embedded FTP server through in-test SOCKS5 and HTTP `CONNECT` proxies, which record the tunneled connections * Document the options in the FTP session factory chapter Signed-off-by: Sharang Gupta <[email protected]>
artembilan
requested changes
Oct 14, 2026
artembilan
left a comment
Member
There was a problem hiding this comment.
Very cool!
Just couple nit-picks.
Thank you!
| sessionFactory.setHost("localhost"); | ||
| sessionFactory.setPort(port); | ||
| sessionFactory.setUsername("foo"); | ||
| sessionFactory.setPassword("foo"); |
Member
There was a problem hiding this comment.
No foo/bar language in the code, please.
Contributor
Author
There was a problem hiding this comment.
Done: the tests use ftpuser / ftppassword now, and the shared mock setup in the SessionFactoryTests moved to a helper method.
Member
|
FYI, we have only couple days left in the current development cycle. Thank you for understanding! |
* Set the `clientMode` to the `FTPClient.PASSIVE_LOCAL_DATA_CONNECTION_MODE` in the `AbstractFtpSessionFactory.setProxy()`, since the server cannot connect back to the client through a proxy; the `getSession()` still fails when the mode is changed afterwards to another one * Use descriptive credentials instead of the placeholder names in the tests Signed-off-by: Sharang Gupta <[email protected]>
Contributor
Author
|
Thank you for the review and for the heads-up on the timeline, @artembilan. Both points are addressed in the new commit, and the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #6485
An FTP server behind a proxy could so far only be reached with the proxy system properties of the JVM (
socksProxyHostand friends), which affect every connection of the application, or by writing a custom session factory. This adds the two options that Artem sketched on the issue.What it adds
AbstractFtpSessionFactory#setProxy(java.net.Proxy), soDefaultFtpSessionFactoryandDefaultFtpsSessionFactoryconnect through a SOCKS proxy, or through an HTTP proxy with theCONNECTtunneling of the JVM. The proxy is passed toFTPClient#setProxy(), which makes the client use it for the control connection and for the passive data connections. Because the server cannot connect back to the client through a proxy, the factory requiresFTPClient.PASSIVE_LOCAL_DATA_CONNECTION_MODEwhen a proxy is set, and fails fast with a message that says so.FtpHttpProxySessionFactory, based onFTPHTTPClient, for an HTTP proxy that requires credentials (sent with the basic scheme). It defaults to, and only accepts, the passive client mode. The name follows theDefault*SessionFactorystyle; the issue mentionedFtpHttpSessionFactory, so please say if you prefer that one.Testing
Developed test first: the new tests do not compile against
main(the API does not exist), and pass with the change.SessionFactoryTests: the proxy is applied to the client beforeconnect(), the client is not proxied by default, and a proxy with the active client mode is rejected.FtpHttpProxySessionFactoryTests: defaults and validation of the new factory.FtpProxySessionFactoryTests: against the embedded Apache FtpServer of the module, through small in-test proxies (LocalProxyServer: a SOCKS5 proxy and an HTTPCONNECTproxy with optional basic authentication) that record the tunneled connections. The tests write, list and read a file through a SOCKS proxy, through an HTTP proxy with the JVM tunneling, and through an HTTP proxy with credentials, and assert that the control connection and the data connections all went through the proxy. Wrong proxy credentials fail the session creation with the proxy's407in the stack trace../gradlew :spring-integration-ftp:checkand./gradlew antorapass locally.