Forums Register Login
Connect to FTP site with Apache commons net FTP client through Proxy

I am trying to run this simple code to connect to FTP site through a proxy.

I am getting the following error:
C:\temp\ftp\test>java.exe -cp ./commons-net-ftp-2.0.jar;. MyTest connecting
java.net.SocketException: Malformed reply from SOCKS server
at java.net.SocksSocketImpl.readSocksReply(SocksSocketImpl.java:87)
at java.net.SocksSocketImpl.connectV4(SocksSocketImpl.java:265)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:437)
at java.net.Socket.connect(Socket.java:519)
at org.apache.commons.net.SocketClient.connect(SocketClient.java:176)
at MyTest.main(MyTest.java:23)
loging out
at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:471<ftp://FTP.java:471>)
at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:534<ftp://FTP.java:534>)
at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:583<ftp://FTP.java:583>)
at org.apache.commons.net.ftp.FTP.quit(FTP.java:794<ftp://FTP.java:794>)
at org.apache.commons.net.ftp.FTPClient.logout(FTPClient.java:697)
at MyTest.main(MyTest.java:39)

I am able to do this using a different FTP client library, ftp4j-1.5.1, using the following code:

So I know the proxy settings are correct.
The java version I used to compile and run my apps is 1.6.0_06 Does anyone can help figure out what is wrong when I use the Apache commons net FTP client?

Thank you

Hi Jon and welcome to Javaranch!

Is that the recommended way to set a proxy using commons-net? Also, download the source code and have a look as to why it could be throwing the NPE at that line. Oh and are you using version 2.0?
Based on what I read on the FAQ for the library, this is the way to connect to FTP through proxy. The version is 2.0. I was not able to make it work and used a different library eventually, ftp4j, which worked fine for my need.

Thank you for your reply

I'm facing the same issue( Exception - Malformed reply from SOCKS server), can any one suggest solution?

I am also facing this kind of issue, any help is greatly appreciated.

Anderson gave himself the promotion. So I gave myself this tiny ad:
ScroogeXHTML 7.1 - RTF to HTML5 / XHTML converter

This thread has been viewed 10413 times.

All times above are in ranch (not your local) time.
The current ranch time is
Feb 21, 2018 22:27:55.