Guest User

Untitled

a guest
Jun 14th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. import java.io.IOException;
  2. import org.apache.commons.net.ftp.*;
  3.  
  4. public class FTPApp {
  5. private static void showServerReply(FTPSClient ftpClient) {
  6. String[] replies = ftpClient.getReplyStrings();
  7. if (replies != null && replies.length > 0) {
  8. for (String aReply : replies) {
  9. System.out.println("SERVER: " + aReply);
  10. }
  11. }
  12. }
  13.  
  14. public static void main(String[] args) {
  15.  
  16. String server = "ftp.availity.com";
  17. int port = 21;
  18. String user = "user";
  19. String pass = "pass";
  20. FTPSClient ftpClient = new FTPSClient();
  21.  
  22. try {
  23. ftpClient.connect( server, port);
  24. showServerReply(ftpClient);
  25. int replyCode = ftpClient.getReplyCode();
  26. if (!FTPReply.isPositiveCompletion(replyCode)) {
  27. System.out.println("Operation failed. Server reply code: " + replyCode);
  28. return;
  29. }
  30. boolean success = ftpClient.login(user, pass);
  31. showServerReply(ftpClient);
  32. if (!success) {
  33. System.out.println("Could not login to the server");
  34. return;
  35. } else {
  36. System.out.println("LOGGED IN SERVER");
  37. }
  38. } catch (IOException ex) {
  39. System.out.println("Oops! Something wrong happened");
  40. ex.printStackTrace();
  41. }
  42. }
  43.  
  44. at org.apache.commons.net.ftp.FTPSClient.execAUTH(FTPSClient.java:242)
  45. at org.apache.commons.net.ftp.FTPSClient._connectAction_(FTPSClient.java:225)
  46. at org.apache.commons.net.SocketClient._connect(SocketClient.java:244)
  47. at org.apache.commons.net.SocketClient.connect(SocketClient.java:202)
  48. at FTPApp.main(FTPApp.java:23)
Add Comment
Please, Sign In to add comment