How to FTP through a SOCKS proxy

SOCKS is a protocol that many proxy servers use to communicate with clients. It allows computers behind a firewall to communicate with computers outside the firewall. During this communication the proxy server acts as a relay for information sent in both directions.  Please refer to the topic SOCKS Proxies for more information on this.

To direct socket communications via the SOCKS proxy, the FTPClient.initSOCKS() static method must be called. If username/password authentication is required, FTPClient.initSOCKSAuthentication() can be used to set the username and password for the SOCKS server. An example is shown below:

FTPClient.initSOCKS("9091", "socksserver");
FTPClient.initSOCKSAuthentication("proxyuser", "proxypassword");

Note that these static methods set the SOCKS properties for the entire Java Virtual Machine – it is not currently possible to set them for a specific instance. This could be especially problematic if used within an application server. A future release will remove this 'feature'.