Skip to content

FTP Consumer Events

The consumer components p6ftd and p6sftp produce events as user(s) make changes to their virtual file systems.

User FTP events can be used to trigger p6 services to process the consequences of those events. Alternatively the inbuilt file component can be used to ‘listen’ to the file system used to represent a users FTP virtual file system.

Note

The latter has traditionally been the approach taken with b2box5

The Exchange generated by the ftp consumer components has the following headers

  • user (The id of the current user)
  • path (The absolute path of teh file/folder in the file system)
  • pathFrom (Only available when action = FILE_MOVED)
  • action ( The FTP action )

FTP Actions

  • FILE_WRITTEN
  • FILE_MOVED
  • FILE_REMOVED
  • FILE_READ
  • FOLDER_ADDED
  • FOLDER_REMOVED

Examples

If the file component is the preferred choice for monitoring file system changes the events generated by the ftp consumer can simply be logged:

from('p6ftpd:///')
    .description('FTP Listener')
    .to("log:p6.ftpd")
    .routeId('FTP_Listener')

Filtering Events

Not all FTP events may be of interest to a p6 service so the event types can be filtered after they are emitted by the consumer:

from('p6sftpd:///')
    .description('SFTP Listener')
    .filter { request ->
        def action = request.getIn().getHeader('action', String.class)
        if( action == "FILE_WRITTEN" || action == "FILE_MOVED" ) true
        else false
    }
    .to('p6cmb://scripts?platform6.request.action=execute&id=FtpFileListener')
    .routeId('SFTP_Listener')

Note

Here we use Groovy in a filter expression returning ‘true’ when the event should be forwarded.

In addition to filtering, message aggregation is a powerful tool to batch FTP consumer events.

See: Camel Aggregation & Strategies