Question

I want to set up an FTP connection using a proxy server with Apache's commons-net.

But looking at this Does FTPClient support FTP connections through an FTP proxy server? has me worried.

I have to meddle with the system properties and the Sun docs state that "If socksProxyHost is specified then all TCP sockets will use the SOCKS proxy server to establish a connection or accept one."
WTH? All TCP sockets? What about my database connections? Or other FTP connections i might want to open at the same time not using a proxy? Will they all be affected?

Is there some other way to do it that doesn't mess with the rest of my application?

Was it helpful?

Solution

You have several ways of using proxies in Java, especially from version 1.5.

  1. Using System Properties: quick & powerfull but limited flexibility
    • You can use use a SOCKS proxy for all TCP connections.
    • You can also set a proxy per protocol, doable for HTTP, FTP and HTTPS
    • For both methods, you can specify a list of hosts that will not use proxy
  2. Using the java.net.Proxy class (Java 1.5+) to set (or not) a Proxy per Connection
  3. Impleting a java.net.ProxySelector (idem) which will determine a Proxy for each Connection according to your criteria

See the detailled Sun technote on networking & proxies.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top