Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.IOException;
- import org.apache.commons.net.ftp.*;
- public class FTPApp {
- private static void showServerReply(FTPSClient ftpClient) {
- String[] replies = ftpClient.getReplyStrings();
- if (replies != null && replies.length > 0) {
- for (String aReply : replies) {
- System.out.println("SERVER: " + aReply);
- }
- }
- }
- public static void main(String[] args) {
- String server = "ftp.availity.com";
- int port = 21;
- String user = "user";
- String pass = "pass";
- FTPSClient ftpClient = new FTPSClient();
- try {
- ftpClient.connect( server, port);
- showServerReply(ftpClient);
- int replyCode = ftpClient.getReplyCode();
- if (!FTPReply.isPositiveCompletion(replyCode)) {
- System.out.println("Operation failed. Server reply code: " + replyCode);
- return;
- }
- boolean success = ftpClient.login(user, pass);
- showServerReply(ftpClient);
- if (!success) {
- System.out.println("Could not login to the server");
- return;
- } else {
- System.out.println("LOGGED IN SERVER");
- }
- } catch (IOException ex) {
- System.out.println("Oops! Something wrong happened");
- ex.printStackTrace();
- }
- }
- at org.apache.commons.net.ftp.FTPSClient.execAUTH(FTPSClient.java:242)
- at org.apache.commons.net.ftp.FTPSClient._connectAction_(FTPSClient.java:225)
- at org.apache.commons.net.SocketClient._connect(SocketClient.java:244)
- at org.apache.commons.net.SocketClient.connect(SocketClient.java:202)
- at FTPApp.main(FTPApp.java:23)
Add Comment
Please, Sign In to add comment