I wish to connect to an FTP server. Trouble is that the internet connection goes through a proxy server. I am using the Jakarta package for the FTP.

The process works as follows, if I understand it correctly:
Step 1 - Connect to proxy server
Step 2 - Connect to FTP server.

If I do step 1 manually first (open Internet explorer and type in the user and password to connect myself to the proxy server), then step 2 works fine.

However, if I do not do this, obviously neither step 1 or 2 work.

Here is what I tried first.............


System.getProperties().put("ftp.proxyHost", "proxy.abc.def");

System.getProperties().put("ftp.proxyPort", "80");

System.getProperties().put("ftp.proxyUser", "auser");

System.getProperties().put("ftp.proxyPassword", "apswd");

Then comes the code for part 2 - ie connect to ftp host -


However, when I run the program and it comes to do the actual connection to the FTP host, part 2 above, I get "java.net.ConnectException: Connection timed out: connect".

So, reading around, I saw bits of advice suggesting I need to connect to a SOCKS server as well. So I put the below code in place.

System.getProperties().put( "socksProxyPort", "80");
System.getProperties().put( "socksProxyHost" ,"proxy.abc.def");

However, this gave me the same error as above.

Then I heard that I need to authenticate myself to the SOCKS server.
So, here is what I wrote to do that:

Authenticator.setDefault(new Authenticator(){
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("auser", "apswd".toCharArray());

I used the same username and passwords as I had used for the ftp.proxyUser and ftp.proxyPassword, because I do not have any other passwords - perhaps this is the incorrect thing to do....?

Then, I got the following exception:
java.net.SocketException: Malformed reply from SOCKS server

Does that mean I am actually connected to the SOCKS server or not, I wonder. I read in a few places that some proxies use SOCKS and some don't. I don't know how to determine whether mine does or not. When I look at the properties of the proxy in Internet explorer, I notice that the SOCKS section is blanked out. I can fill it in myself, of course, but my program still has the same errors as above.

Has anyone else had a similar problem and know how to get around it? Yours desperately..