Pages Navigation Menu

Coding is much easier than you think

Connect and Login to FTP Server using Java

Connect and Login to FTP Server using Java

 
** UPDATE: FTP Complete tutorial now available here.
 

package com.simplecode.com;

import java.io.IOException;

import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPConnectionClosedException;

public class FtpLogin {
	public static void main(String[] args) throws IOException {
		FTPClient ftpClient = new FTPClient();
		boolean result;
		try {
			// Connect to the localhost
			ftpClient.connect("localhost");

			// login to ftp server
			result = ftpClient.login("admin", "admin");
			if (result == true) {
				System.out.println("Successfully logged in!");
			} else {
				System.out.println("Login Fail!");
				return;
			}
		} catch (FTPConnectionClosedException e) {
			e.printStackTrace();
		} finally {
			try {
				ftpClient.disconnect();
			} catch (FTPConnectionClosedException e) {
				System.out.println(e);
			}
		}

	}
}

About Mohaideen Jamil


I'm a Full stack developer of IT exp in J2EE, AngularJs, MicroServices, Docker, Spring (Boot, MVC, Cloud), Bluemix, DevOps. Follow me on Facebook or Google Plus. If you like my tutorials, consider making a donation to this charity, thanks.

Advertisements
%d bloggers like this: