SFTP Connection Setup

Overview

Defines a connection to an SFTP server. Store the connection JSON in the connections/ directory.

Connection File: connections/sftp-server.json

JSON
{
  "name": "sftpServer",
  "type": "sftp",
  "url": "{{sftp.host}}",
  "port": 22,
  "username": "{{sftp.username}}",
  "password": "{{sftp.password}}",
  "remoteDirectory": "{{sftp.remoteDirectory}}"
}

Properties in config/application.properties (or PlatformManager environment variables):

sftp.host=sftp.example.com
sftp.username=im-user
sftp.password=secret
sftp.remoteDirectory=/upload/pricefx

Using the Connection in Routes

Reference by connection name in the SFTP URI:

XML
<routes xmlns="http://camel.apache.org/schema/spring">
    <route id="exportToSftp">
        <from uri="timer://trigger?repeatCount=1"/>
        <to uri="pfx-api:fetch?objectType=PX&amp;filter=exportFilter"/>
        <to uri="pfx-csv:marshal"/>
        <to uri="pfx-sftp:upload?connection=sftpServer&amp;fileName={{sftp.path}}/export_${date:now:yyyyMMdd}.csv"/>
    </route>
</routes>

Common Pitfalls

  • Never hardcode credentials — always use {{property}} placeholders

  • The name field in the JSON must match the connection= parameter in the route URI

  • remoteDirectory must exist on the SFTP server before the route runs

  • For key-based authentication, use privateKeyFile and privateKeyPassphrase instead of password