Guest User

Untitled

a guest
Aug 26th, 2018
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. FTP connection through proxy with Java
  2. Properties props = System.getProperties();
  3. props.put("ftp.proxySet", "true");
  4. // dummy details
  5. props.put("ftp.proxyHost", "proxy.example.server");
  6. props.put("ftp.proxyPort", "8080");
  7.  
  8. conn = url.openConnection();
  9. String password = "username:password";
  10. String encodedPassword = new String(Base64.encodeBase64(password.getBytes()));
  11. conn.setRequestProperty("Proxy-Authorization", encodedPassword);
  12.  
  13. private static class MyAuthenticator extends Authenticator {
  14. private String username;
  15. private String password;
  16. public MyAuthenticator(String username, String password) {
  17. super();
  18. this.username = username;
  19. this.password = password;
  20. }
  21. @Override
  22. protected PasswordAuthentication getPasswordAuthentication() {
  23. return new PasswordAuthentication(username, password.toCharArray());
  24. }
  25. }
  26.  
  27. public static void main(String[] args) {
  28. Authenticator.setDefault(new MyAuthenticator("foo", "bar"));
  29. System.setProperty("...", "...");
  30. }
Add Comment
Please, Sign In to add comment