Downloading Files using Camel and FTP

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

Create a Maven Project

Create a Maven Project

  • groupId: com.skills421.examples.camel
  • artifactId:  CamelBasics
  • version: 0.0.1-SNAPSHOT

Update Pom.xml

<project xmlns="" xmlns:xsi=""     xsi:schemaLocation="">


<!-- 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()


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

Run the Test

Run the JUnit Test and you should see your files downloaded from your remote ftp server to your local directory.

Test Using a Free Public FTP Server

Choose an ftp server from

  • hostname:
  • login: demo
  • password: password

FTP from Server using bash commands:

Password: password

ftp> ls
list the files in the directory

ftp> get readme.txt
ftp> bye

more readme.txt

FTP from Server using FTPCopierTest

Now edit as follows

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

note: you will need to change the localPath to something meaningful for your machine.

Run the FTPCopierTest JUnit test and the file should download into your localPath


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 )

Facebook photo

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

Connecting to %s