• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Jon Mena
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Jon Mena
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm facing the same issue( Exception - Malformed reply from SOCKS server), can any one suggest solution?

Thanks,
Karthik
 
Dhamodharan Ramalingam
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am also facing this kind of issue, any help is greatly appreciated.

Thanks,
Dhamu
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic