aspose file tools*
The moose likes Other Open Source Projects and the fly likes Connect to FTP site with Apache commons net FTP client through Proxy Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Connect to FTP site with Apache commons net FTP client through Proxy" Watch "Connect to FTP site with Apache commons net FTP client through Proxy" New topic
Author

Connect to FTP site with Apache commons net FTP client through Proxy

Jon Mena
Greenhorn

Joined: Nov 24, 2010
Posts: 2
Hello,

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
java.lang.NullPointerException
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

Jon
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

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?


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
Jon Mena
Greenhorn

Joined: Nov 24, 2010
Posts: 2
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

Jon
Karthik Ng
Greenhorn

Joined: Mar 13, 2012
Posts: 1
Hi,
I'm facing the same issue( Exception - Malformed reply from SOCKS server), can any one suggest solution?

Thanks,
Karthik
Dhamodharan Ramalingam
Greenhorn

Joined: Mar 29, 2012
Posts: 1
I am also facing this kind of issue, any help is greatly appreciated.

Thanks,
Dhamu
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Connect to FTP site with Apache commons net FTP client through Proxy