Java
Java
Connect to FTP Through an HTTP Proxy
See more FTP Examples
Demonstrates connecting through an HTTP proxy using HttpProxyHostname, HttpProxyPort, HttpProxyUsername, HttpProxyPassword, HttpProxyAuthMethod, and HttpProxyDomain.
Background: Many corporate networks force outbound traffic through an HTTP proxy, which reaches the FTP control connection via the
CONNECT method — so the proxy must permit CONNECT to the FTP port. HttpProxyAuthMethod is Basic or NTLM, with HttpProxyDomain supplying the Windows domain for NTLM. This is distinct from a traditional FTP proxy, which speaks FTP itself.Chilkat Java Downloads
import com.chilkatsoft.*;
public class ChilkatExample {
static {
try {
System.loadLibrary("chilkat");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load.\n" + e);
System.exit(1);
}
}
public static void main(String argv[])
{
boolean success = false;
CkFtp2 ftp = new CkFtp2();
ftp.put_Hostname("ftp.example.com");
ftp.put_Username("myFtpLogin");
// The HTTP proxy through which the FTP control connection is made. Common ports are 8080 and
// 3128.
ftp.put_HttpProxyHostname("proxy.example.com");
ftp.put_HttpProxyPort(8080);
// Proxy authentication, if required. HttpProxyAuthMethod is "Basic" or "NTLM"; HttpProxyDomain
// is the Windows domain used for NTLM.
ftp.put_HttpProxyUsername("myProxyLogin");
ftp.put_HttpProxyPassword("myProxyPassword");
ftp.put_HttpProxyAuthMethod("NTLM");
ftp.put_HttpProxyDomain("CORP");
// Normally you would not hard-code the password in source. You should instead obtain it
// from an interactive prompt, environment variable, or a secrets vault.
ftp.put_Password("myPassword");
success = ftp.Connect();
if (success == false) {
System.out.println(ftp.lastErrorText());
return;
}
System.out.println("Connected through the HTTP proxy.");
success = ftp.Disconnect();
if (success == false) {
System.out.println(ftp.lastErrorText());
return;
}
}
}