title: Connect to FTP Server via FTP Proxy
body: <p>I try to poll files from a ftp server using ftp4j. My application runs behind a Squid Proxy, so I use HTTPTunnelProxyConnector to connect to the proxy. But when trying to connect, it throws the following exception:</p>
  
  <pre><code>java.net.SocketException: Can't connect to SOCKS proxy:Connection refused
  at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:397)
  at java.net.Socket.connect(Socket.java:529)
  at it.sauronsoftware.ftp4j.FTPConnector.tcpConnectForCommunicationChannel(FTPConnector.java:208)
  at it.sauronsoftware.ftp4j.connectors.HTTPTunnelConnector.httpConnect(HTTPTunnelConnector.java:111)
  at it.sauronsoftware.ftp4j.connectors.HTTPTunnelConnector.connectForCommunicationChannel(HTTPTunnelConnector.java:195)
  at it.sauronsoftware.ftp4j.FTPClient.connect(FTPClient.java:1036)
  at it.sauronsoftware.ftp4j.FTPClient.connect(FTPClient.java:1003)
  </code></pre>
  
  <p>This is the code snippet I use for the connection:</p>
  
  <pre><code>FTPClient client = new FTPClient();
  client.setType(FTPClient.TYPE_BINARY);
  client.setPassive(true);
  
  HTTPTunnelConnector conn = new HTTPTunnelConnector("XX.XX.XX.XX", 80);
  client.setConnector(conn);
  
  try {
      client.connect("some.ftp.server.com");      // here I get the Exception
  
      ....
  </code></pre>
  
  <p>It seems that regardless of which kind of Connector I use, it always uses a SocksSocketImpl, which fails because there is no Socks Proxy.
  I already tried setting the proxy manually in Socket class, but get <code>java.lang.IllegalArgumentException: Invalid Proxy</code> for Proxy Type HTTP. </p>
  
  <p>I can connect to the server with wget and the environment variable ftp_proxy set, so my problem seems to have nothing to do with proxy configuration, but I am no network crack, so I am not pretty sure...</p>
  
  <p>I have no influence on the type of proxy installed, so I can not simply use another one.
  Any hint anyone please?</p>