Skip to content

FTP

This component provides access to remote file systems over the FTP and SFTP protocols.

For more information about FTP: https://camel.apache.org/ftp.html

Examples

Template: Dev_BaseRoute.groovy

Listener

Pull files from a SSHD server to the Platform 6 instance directory /opt/p6core.data/tmp/DLN.

${addRoutes} :=

from("sftp://test.amalto.io:2222/in?password=TEST&antInclude=*&move=../processed")
    .description('SFTP:test listener')
    .to("file:/opt/p6core.data/tmp")
    .threads(2,10)
    .to("p6cmb://scripts?platform6.request.action=execute&id=Handle_sFTP_Content")
    .routeId("mySFTPRoute")

${destroyRoutes} :=

p6.camel.destroyRoute('mySFTPRoute')

Producer

Expose all XML files over SFTP from the Platform 6 instance directory /opt/p6core.data/tmp/DLN and made them available on sftp://test.amalto.io:2222/in.

${addRoutes} :=

from("file:/opt/p6core.data/tmp/DLN?antInclude=*.xml&move=.processed")
    .description('FTP File Drop Processor')
    .to("sftp://test.amalto.io:2222/in?password=TEST")
    .routeId('myFileRoute')

${destroyRoutes} :=

p6.camel.destroyRoute('myFileRoute')

Handling SFTP Connection Failures

When using the Camel SFTP component, connection errors (bad credentials, host unavailable, etc.) are not fatal by default. Understanding how to configure error handling is critical to avoid silent failures or endless retries.

Problem

By default, an SFTP consumer:

  • Runs asynchronously as a polling task.
  • Silently retries on connection failures.
  • Does not propagate exceptions to the route or onException() blocks.

This means if credentials are wrong or the server is unreachable, the route will:

  • Stay in a “running” state.
  • Retry indefinitely every delay interval (e.g. every 20 seconds).
  • Not trigger any onException() handlers.

Correct Configuration for Reliable Error Handling

To make Camel surface SFTP connection failures properly, always include these URI parameters:

throwExceptionOnConnectFailed=true
bridgeErrorHandler=true

Example

import org.apache.camel.LoggingLevel

from('sftp://my.server.com:22/incoming'
    // Username to use for login
    + '?username=myuser'
    // Password to use for login
    + '&password=secret'
    // Fail immediately if the SFTP connection cannot be established (e.g., bad credentials or network error)
    + '&throwExceptionOnConnectFailed=true'
    // Route connection errors to Camel's error handler so they can be caught by onException()
    + '&bridgeErrorHandler=true'
    // Default poll delay between runs, in ms
    + '&delay=20000'
    // Forces Camel to close the SFTP session after each cycle
    '&disconnect=true')
    .routeId('SftpImport')
    .log(LoggingLevel.DEBUG, '📦 Processing file: ${header.CamelFileName}')
    .to('file:/data/incoming')

What Each Parameter Does

Parameter Default Purpose
throwExceptionOnConnectFailed=true false Forces Camel to throw an exception immediately when the SFTP connection fails instead of silently retrying.
bridgeErrorHandler=true false Bridges consumer-level exceptions (like SFTP connection errors) into Camel’s routing error handler, allowing them to be caught by onException().
disconnect=true false Forces Camel to close the SFTP session after each polling cycle instead of keeping the connection open. This prevents stale or half-open connections, and ensures that subsequent polls use a fresh authenticated session. Particularly useful for unstable or short-lived SFTP servers.

All the SFTP component parameters can be found in http://camel.apache.org/components/4.14.x/sftp-component.html

Important Behavior Notes

  • Even with throwExceptionOnConnectFailed=true, Camel’s polling consumer will still retry at the next delay interval — unless you explicitly stop the route.
  • To fully prevent retries after a fatal connection failure, stop the route programmatically.

Example

onException(com.jcraft.jsch.JSchException)
    .handled(true)
    .log('❌ SFTP connection failed: ${exception.message}. Route will be stopped.')
    .process { exchange ->
        p6.log.warn('Stoping route...')
        p6.camel.destroyRoute(p6.P6_CURRENT_ROUTE)
    }        
This ensures the route stops permanently after a failed SFTP connection, instead of retrying every 20 seconds.

Warning

The route have to be restarted manually