FTP connection through proxy with Java
13,463
How about using the FTPHTTPClient when you want to use a proxy;
if(proxyHost !=null) {
System.out.println("Using HTTP proxy server: " + proxyHost);
ftp = new FTPHTTPClient(proxyHost, proxyPort, proxyUser, proxyPassword);
}
else {
ftp = new FTPClient();
}
Author by
ceej23
Web developer in Geelong, Australia Huge passion for Drupal development
Updated on June 14, 2022Comments
-
ceej23 almost 2 years
I'm trying to connect to an FTP server through a proxy using org.apache.commons.net.ftp.FTPClient. Pretty sure the system properties are getting set correctly as per following:
Properties props = System.getProperties(); props.put("ftp.proxySet", "true"); // dummy details props.put("ftp.proxyHost", "proxy.example.server"); props.put("ftp.proxyPort", "8080");
Creating a connection raises a UnknownHostException which I'm pretty sure means the connection isn't making it past the proxy.
How can user credentials be passed through to the proxy with this connection type.
BTW, I can successfully create a URLConnection through the same proxy using the following; is there an equivalent for the Apache FTPClient?
conn = url.openConnection(); String password = "username:password"; String encodedPassword = new String(Base64.encodeBase64(password.getBytes())); conn.setRequestProperty("Proxy-Authorization", encodedPassword);