Skip to content

Overview

Concepts and Principles

Development

Overview

IDEs

API Explorer

Releases

Release Notes

TORO Integrate

Coder Studio

Coder Cloud

Bug Reports

Search

FTP Client Endpoint

The FTP Client Endpoint enables developers to write integrations 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 TORO Integrate then needs to process.

Properties

Property Default Description
Host (required) The remote host to connect to
Protocol (required) The protocol of the remote host. Possible values: FTP, FTPS, SFTP
Port (required) The server port
Username (required) The username used to login
Password (required) The password used to login
Directory (required) The remote directory to poll for changes
Polling Interval (required) The interval in seconds, at which TORO Integrate checks for changes
Service (required) The service to execute when the endpoint is triggered
Post Action (required) The action taken after invoking the service. Possible values:
  • Delete
  • Move

    This option will require Destination, which corresponds to the destination path, to be set.

  • Rename

    This option requires New Name, which corresponds to the new name of the file, to be set. The variable {filename} can be used to reference the original filename.

Do Action On Exception false Flag determining whether the Post Action needs to be executed regardless of the exception
Passive false Flag determining whether the login should be in passive mode
Run As 'Anonymous' The user to run the service in behalf of. This is logged to tracker
Log to Tracker false Flag determining whether executions should be logged to the tracker
Document Type 'FTP Client' The document type to be registered to the tracker when this endpoint is triggered

Service

When the endpoint is triggered, the following variables are exposed to the configured service:

Name Type Description
parameters java.util.Map Contains all the variables below
esbPackage ESBPackage The Integrate Package that contains this endpoint
properties java.util.Map Contains all the properties associated with the endpoint
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.io.File 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)
internalId java.lang.String Tracker internal ID. If the endpoint was configured to not track, this value will be null

Examples

Gloop as a Service

Consider this integration using Gloop that sends the file that triggered the endpoint to an remote FTP server:

File-sending service

(1) Takes 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):

File-sending service's inputs

(6) The value of bytes is then written to the remote representation of the file resolved by the previous line.

More Gloop

The distribution ships with an Integrate Package called examples, which contains services (including the above example) demonstrating more use cases.

Groovy Script as a 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
[ 
    'properties',
    'context',
    'jobDataMap',
    'job',
    'file', 
    'filename', 
    'inputStream', 
    'reader',
    'multipartFile',
    'internalId' ].each {

    println "$it\t : " + this[it]
}

When the endpoint is triggered - in this case, an email is sent to the configured mail address - the console prints accordingly:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
properties   : [ <ommitted> ]
context  : JobExecutionContext: <ommitted>
jobDataMap   : [ <ommitted> ]
job  : io.toro.integrate.core.endpoint.impl.vfs.VFSClientJobWrapper@5f10fee7
file     : /tmp/watch-me/whip.whip
filename     : /tmp/watch-me/whip.whip
inputStream  : java.io.FileInputStream@55c780af
reader  : java.io.InputStreamReader@23c45bd
multipartFile    : io.toro.integrate.core.util.ESBMockMultipartFile@3a1fa99c
internalId   : null

In combination with the Groovy extension modules, we can write scripts that address more advance use cases, such as:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
// get a groovy.sql.SQL object that points to the connection pool called 'customers'
int count = 0
'customers'.sql() {  sql ->
    def query = 'insert into my_customers ( id, first_name,  last_name, address1, address2, city, state, postcode ) values ( ?, ?, ?, ?, ?, ?, ?, ? )'
    sql.withBatch(1000, query) { ps ->
        // iterate over the csv file, skipping the first row
        file.eachRecord(1) { it ->
            ps.addBatch(it[0], it[1], it[2], it[3], it[4], it[5], it[6], it[7])
            count++
            if (count % 1000 == 0) println "processed ${count}"
        }
    }
}

This script iterates a comma-separated value (CSV) file and batch inserts the data in the database customers.

Groovy Method as a 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
class Reporter {

    def sendFileAsEmailBody( String content ) {
        // smtps format is smtp[s]://<login>:<password>@<smtp-server>[:port]/<Subject>
        'smtps://myEmail:password@server/Daily Report'.send( [to: 'daily-reports@work.com'], content );
    }
}
This loads up the content of the file and sends it as an email body to daily-reports@work.com.

Warning

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.