FTP client endpoint
The FTP client endpoint enables developers to write services that react to changes occurring in a remote FTP/FTPS/SFTP directory. This may be applicable to scenarios where other systems manipulate files in a remote filesystem, which Martini then needs to process.
Properties
General configuration
Property | Default | Description |
---|---|---|
Name | (required) | The name of the endpoint. |
Service | (required) | The service to execute when the endpoint is triggered. |
Run As | Anonymous |
The user to run the service in behalf of. This is logged to Tracker. |
Document Type | <Name of endpoint type> | The document type to be used when adding documents to Tracker as this endpoint is triggered. |
Auto Start | true |
Whether or not to automatically start the endpoint upon package startup. |
Log To Tracker | false |
Flag determining whether executions should be logged to Tracker. |
Replicated | true |
If this endpoint is configured on a Martini instance that's running in a cluster, replicated will determine whether to run the endpoint on all instances, or only the elected leader node in the cluster. When this is checked, all instances will run the endpoint. When it's unchecked, only the leader node will run the endpoint. |
FTP client-specific configuration
Property | Default | Description |
---|---|---|
Polling Interval | (required) | The interval in seconds, at which Martini checks for changes. |
Directory | (required) | The remote directory to poll for changes. |
Events | Addition |
The type of events this endpoint should monitor. |
Connection configuration
Property | Default | Description |
---|---|---|
Username | (required) | The username used to log in to the FTP server. |
Password | (required) | The password used to log in to the FTP server. |
Host | (required) | The remote host to connect to. |
Port | (required) | The server port. |
Protocol | (required) | The protocol of the remote host. Possible values: FTP , FTPS , SFTP . |
Connection Timeout (ms) | 0 |
The maximum time to wait while creating a connection to the server. |
Socket Timeout (ms) | 0 |
The maximum time to wait for a packet before dropping the connection. |
File system options configuration
Property | Default | Description |
---|---|---|
Passive | false |
Flag determining whether data connections made to the FTP server should be active (unchecked), or passive (checked). |
User Directory is Root | true |
Flag determining whether to treat the user directory as the root directory. |
Default Date Format | The main date format that will be used to parse file timestamps. | |
Recent Date Format | The secondary date format that will be used to parse file timestamps, typically those less than a year old. | |
Control Encoding | ISO-8859-1 |
The character encoding to be used by the FTP control connection. |
Server Language Code | en |
A two-letter ISO-639 language code that will be used to configure the set of month names used by the file timestamp parser. |
Server Time Zone Id | The time zone to be specified corresponding to that known to be used by an FTP server in file listings. | |
File Type | ASCII |
The character encoding of the files from the FTP server. |
Service
When the endpoint is triggered, the following variables are exposed to the configured service:
General parameters
Name | Type | Description |
---|---|---|
$trackerId |
java.lang.String |
The Tracker document internal ID. If the endpoint was configured to not track, this value will be null . |
$tracker |
io.toro.martini.tracker.Tracker |
The Tracker object. If the endpoint was configured to not track, this value will be null . |
martiniPackage |
MartiniPackage |
The Martini package that contains the endpoint. |
parameters |
java.util.Map |
A map containing all the endpoint specific parameters. |
properties |
java.util.Map |
A map containing containing all the properties associated with the endpoint. |
FTP client-specific parameters
Name | Type | Description |
---|---|---|
context |
org.quartz.JobExecutionContext |
The Quartz context. |
jobDataMap |
org.quartz.JobDataMap |
The Quartz job data map. |
job |
org.quartz.Job |
The Quartz job. |
file |
java.nio.file.Path |
The file whose change triggered the endpoint. |
filename |
java.lang.String |
The absolute path of the file . |
inputStream |
java.io.InputStream |
An open InputStream , pointing to the file. The stream is automatically closed after the service executes. |
reader |
java.io.Reader |
An open Reader , pointing to the file. The reader is automatically closed after the service executes. |
multipartFile |
org.springframework.web.multipart.MultipartFile |
A multipart file pointing to the file. |
bytes |
byte[] |
Contains all file data. This variable is only created if your method has a parameter that matches the name (therefore scripts will never have this variable since they don't declare variables). |
content |
java.lang.String |
Contains all file data. This variable is only created if your method has a parameter that matches the name (therefore scripts will never have this variable since they don't declare variables). |
Examples
Gloop as service
Consider this application using Gloop that sends the file that triggered the endpoint to an remote FTP server:
(1) Retrieves the credentials of the FTP server from the package properties.
(5) When the service is executed, this fetches the remote representation of the file matching filename
from the input (provided by the endpoint):
(6) The value of bytes
is then written to the remote representation of the file resolved by the previous line.
Want more examples?
The distribution ships with a Martini package called examples
, which
contains services (including the above example) demonstrating more use cases.
Groovy script as service
Consider this Groovy script that simply prints the available variables in the context:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
When the endpoint is triggered - the console will show logs similar to the following:
1 2 3 4 5 6 7 8 9 10 |
|
Groovy method as service
By using a Groovy class method as the service configured to the endpoint, we get access to additional variables
content
and bytes
. Consider the following script:
1 2 3 4 5 6 7 |
|
daily-reports@work.com
with subject
Daily Report
.
Use inputStream
or file
if reading large files
The use of content
and bytes
is suited only for cases where the expected size of the file is small.
Otherwise, reading via the inputStream
, or accessing the file
directly is recommended.