Martini Invoking Services via a FTP Trigger
Overview
The FTP Client Trigger in Martini enables services to react to changes in a remote FTP/FTPS/SFTP directory. This trigger is ideal for scenarios where there is a need to process files manipulated by other systems in a remote filesystem.
Properties
General Configuration
Refer to for general configuration properties.
FTP Client-Specific Configuration
Configure the trigger with properties specific to FTP operations, such as polling intervals, directory to monitor, and event types to respond to.
Property | Default | Description |
---|---|---|
Polling Interval | (required) | The interval in seconds for Martini to check for changes. |
Directory | (required) | The remote directory to poll for changes. |
Events | Addition |
Types of events the trigger should monitor. |
Connection Configuration
Set up connection details for the FTP server.
Property | Default | Description |
---|---|---|
Username | (required) | Username for FTP server login. |
Password | (required) | Password for FTP server login. |
Host | (required) | Remote host address. |
Port | (required) | Server port. |
Protocol | (required) | Protocol (FTP, FTPS, SFTP). |
Connection Timeout (ms) | 0 |
Maximum time for connection establishment. |
Socket Timeout (ms) | 0 |
Maximum time for data packet transfer. |
File System Options Configuration
Configure additional file system options for the FTP connection.
Property | Default | Description |
---|---|---|
Passive | false |
Data connection mode: active (unchecked) or passive (checked). |
User Directory is Root | true |
Treat user directory as root directory. |
Default Date Format | Main format for file timestamps. | |
Recent Date Format | Secondary format for recent file timestamps. | |
Control Encoding | ISO-8859-1 |
Character encoding for FTP control connection. |
Server Language Code | en |
Language code for month names in file timestamps. |
Server Time Zone Id | Time zone used by the FTP server. | |
File Type | ASCII |
Character encoding of files from the FTP server. |
Service Parameters
General Parameters
Refer to for general service parameters.
FTP Client-Specific Parameters
Parameters available to services triggered by this trigger.
Name | Type | Description |
---|---|---|
context |
org.quartz.JobExecutionContext |
Quartz scheduler context. |
jobDataMap |
org.quartz.JobDataMap |
Quartz job data map. |
job |
org.quartz.Job |
Quartz job instance. |
file |
java.nio.file.Path |
File triggering the endpoint. |
filename |
java.lang.String |
Absolute path of file . |
inputStream |
java.io.InputStream |
Open InputStream to the file. |
reader |
java.io.Reader |
Open Reader to the file. |
multipartFile |
org.springframework.web.multipart.MultipartFile |
MultipartFile pointing to the file. |
bytes |
byte[] |
File data in byte array. |
content |
java.lang.String |
File data as a string. |
Examples
Scripting Example
Consider a script (Groovy, JavaScript, etc.) that logs the details of the file that triggered:
1 2 |
|
Handling File Content
Example of processing the file content:
1 2 3 |
|
Advanced File Handling
Using inputStream
or direct file access for more advanced file handling:
1 2 3 |
|
Use inputStream
or file
for large files
For handling large files, prefer using inputStream
or direct file access to avoid memory issues.
FTP Server Trigger
The FTP Server Trigger in Martini allows for the setup of an FTP server to host services in a Martini package as virtual directories. This facilitates interaction with Martini services through standard FTP operations.
Directory Structure
Services in a Martini package are exposed as virtual directories on the FTP server:
1 2 3 4 5 6 7 |
|
Authentication
Credentials for authenticating to the FTP server can be configured through users and groups.
FTP Client Access
The directory structure of the FTP server can be navigated using FTP clients like FileZilla.
File Processing
Files uploaded to service
virtual directories initiate the corresponding service. The output or error is written back to the same directory with -output
or -error
appended to the filename. For instance, employees.csv
will result in employees.csv-output
.
File Deletion
Uploaded files are automatically removed after the service is invoked.
Properties
General Configuration
Property | Default | Description |
---|---|---|
Name | (required) | Name of the trigger. |
Document Type | FTP Server |
Document type for Tracker logging when this trigger is fired. |
Auto Start | true |
Whether to automatically start the trigger upon package startup. |
Log to Tracker | false |
Whether executions should be logged to Tracker. |
FTP Server-Specific Configuration
Property | Default | Description |
---|---|---|
Port | 1 |
Valid port number (1-65535). |
Users | (none) | Users allowed to log in. |
Groups | (none) | Groups allowed to log in. |
Service Parameters
General Parameters
Refer to the general parameters documentation for more details.
FTP Server-Specific Parameters
Name | Type | Description |
---|---|---|
file |
java.nio.file.Path |
File initiating the trigger. |
filename |
java.lang.String |
Absolute path of file . |
inputStream |
java.io.InputStream |
Open InputStream to the file. Automatically closed after execution. |
reader |
java.io.Reader |
Open Reader to the file. Automatically closed after execution. |
multipartFile |
MultipartFile |
MultipartFile pointing to the file. |
bytes |
byte[] |
File data in byte array. Available if method parameter matches the name. |
content |
java.lang.String |
File data as a string. Available if method parameter matches the name. |
Example
Scripting Example
An example script that logs the available variables in the context:
1 2 3 |
|
File Handling Example
An example demonstrating how to process file content:
1 2 3 |
|
Large File Handling
For large files, use inputStream
or direct file access to manage memory efficiently.