FTPS client behind a proxy server using apache commons net

强颜欢笑 提交于 2019-12-06 21:58:32

Its possible..see the link below....

http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/java/net/ProxySelector.java

Well using Apache's common lib to access FTP using proxy server, please set the RemoteVerificationEnabled to false after creation of FTPClient object.

eg:

FTPClient fc = new FTPClient();  
fc.setRemoteVerificationEnabled(false);  

You can use java.net.Proxy class which is for Java 1.5 and above, this is used to set or unset the Proxy per connection basis

By using the java.net.ProxySelector, will determine a Proxy for each Connection.

as observed it's an old topic but the answer was not properly delivered.

Taking a look on commons apache examples, we can find the following class that explains in details a good sort of available configurations and operations: https://commons.apache.org/proper/commons-net/examples/ftp/FTPClientExample.java

Regarding your question, the most simple and effective way to configura a proxy on FTPClient is:

FTPClient ftp = new FTPHTTPClient("proxyHost", 8080);

Being necessary you can also pass the proxy user and password, as follows:

FTPClient ftp = new FTPHTTPClient("proxyHost", 8080, "proxyUser", "proxyPass");

In case of doubts to where obtain a more recent version of commons.net, follow bellow the maven reference:

<dependency>
    <groupId>commons-net</groupId>
    <artifactId>commons-net</artifactId>
    <version>3.5</version>
</dependency>

And remember, don't put the proxy hardcoded because you might need to run it in different locattions, create a different FTPClient instance based in the existence of some arguments.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!