Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- FTP connection through proxy with Java
- Properties props = System.getProperties();
- props.put("ftp.proxySet", "true");
- // dummy details
- props.put("ftp.proxyHost", "proxy.example.server");
- props.put("ftp.proxyPort", "8080");
- conn = url.openConnection();
- String password = "username:password";
- String encodedPassword = new String(Base64.encodeBase64(password.getBytes()));
- conn.setRequestProperty("Proxy-Authorization", encodedPassword);
- private static class MyAuthenticator extends Authenticator {
- private String username;
- private String password;
- public MyAuthenticator(String username, String password) {
- super();
- this.username = username;
- this.password = password;
- }
- @Override
- protected PasswordAuthentication getPasswordAuthentication() {
- return new PasswordAuthentication(username, password.toCharArray());
- }
- }
- public static void main(String[] args) {
- Authenticator.setDefault(new MyAuthenticator("foo", "bar"));
- System.setProperty("...", "...");
- }
Add Comment
Please, Sign In to add comment