Using FTP Proxy with apache commons-net
Asked Answered
H

1

7

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?

Hairdresser answered 9/7, 2009 at 14:8 Comment(0)
W
7

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.

Walkerwalkietalkie answered 19/7, 2009 at 18:57 Comment(3)
Well, nowadays the SocketFactory is the way to go -- quoting Commons-Net 3.3 documentation commons.apache.org/proper/commons-net/apidocs/org/apache/… "Of special note is the setSocketFactory method ... This is especially useful for adding SSL or proxy support "Preposterous
@SamsonScharfrichter You can add this as another answer, which it is :). Over time, it should get more upvotes than this one and be more visible to people coming back to this question.Walkerwalkietalkie
you can also update your "authoritative answer"... I'm feeling lazy 0:)Preposterous

© 2022 - 2024 — McMap. All rights reserved.