Downloading Files using Camel and FTP

In this blog, we will download files from a Server using FTP and store them in a local directory

Add Additional Dependencies

In order to use FTP we need to add the camel-ftp artifact to the pom.xml as follows:

<project xmlns="" xmlns:xsi=""

		<!-- Core Camel -->
		<!-- Needed for the FTP Component -->

		<!-- JUnit for testing -->





Create the code as follows:

package com.skills421.examples.camel.basics;

import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;

public class FTPCopier
	public String getFtpPath(String type, String url,String remotePath,String username,String password)
		StringBuilder ftpBuilder = new StringBuilder(type);

		return ftpBuilder.toString();

	public void ftpDownload(String url,String remotePath,final String localPath,String username,String password) throws Exception
		CamelContext context = new DefaultCamelContext();

		final String ftpPath = this.getFtpPath("ftp",url, remotePath, username, password);

		context.addRoutes(new RouteBuilder()
			public void configure()



Edit as follows:

package com.skills421.examples.camel.basics;

import static org.junit.Assert.*;

import org.junit.Test;

public class FTPCopierTest

	public void downloadFTPDir()
		FTPCopier copier = new FTPCopier();

		String url = "";
		String remotePath = "myfiles";
		String localPath = "/Users/johndunning/Desktop/Camel/CamelOut";
		String username = "username";
		String password = "password";

			copier.ftpDownload(url, remotePath, localPath, username, password);
		catch (Exception e)


Note that you will need to define your own FTP Server to use to test this.

Run the JUnitTest

Assuming you have configured your FTPServer correctly, you should see that the files have been downloaded into the local directory that you specified.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s