Pages Navigation Menu

Coding is much easier than you think

Create Directory on FTP Server

Create Directory on FTP Server

In this section you will learn how to create directory on FTP server using java.

Create Directory :

You can create new directory on FTP server ,by using FTPClient class method which is mentioned bellow –

boolean makeDirectory(String name) : This method creates new directory on your FTP server. name is your mentioned name of directory.It may be relative as well as absolute.
Here is example :

ftpClient.makeDirectory(“ftpNew”) ; // relative path. It will create directory “ftpNew” in the current directory

ftpClient.makeDirectory(“ftpNew”) ; //absolute path. It will create directory “ftpNew” under server?s root directory.

Example : In this example we are creating new directory in ftp server.


import java.io.IOException;

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

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

			// login to ftp server
			result = ftpClient.login("admin", "admin");

			if (result == true) {
				System.out.println("Logged in Successfully !");
			} else {
				System.out.println("Login Fail !");
			// Changing the working directory
			result = ftpClient.changeWorkingDirectory("/FtpNew");

			if (result == true) {
			System.out.println("New Directory is created on Ftp Server!");
			} else {
			System.out.println("Unable to create new directory!");
		} catch (FTPConnectionClosedException exp) {
		} finally {
			try {
			} catch (FTPConnectionClosedException exe) {


Output :


Logged in Successfully !
New Directory is created on Ftp Server!

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.

%d bloggers like this: