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 Server Endpoint

The FTP Server Endpoint allows developers to setup an FTP server that hosts the available services in an Integrate Package as virtual directories:

1
2
3
4
5
6
7
.
└── {package-name}
    └── {class-name}
        ├── {service1}
        ├── {service2}
        ├── ...
        └── {serviceN}

Credentials used to authenticate to the FTP server are configurable with users and groups.

Browsing

You can navigate the complete directory structure of the started FTP server using FTP clients such as FileZilla.

Files uploaded in the service virtual directories triggers the corresponding service that contains it. After a file gets processed, the output (or error) is written to the same directory, using the same filename appended with -output (or -error). For example, a processed employees.csv will produce a new file called employees.csv-output. These files are stored temporarily on disk, and the underlying Java Virtual Machine is configured to delete on exit.

Note

Uploaded files are deleted after the service is invoked.

Properties

Property Default Description
Port (required) A valid port between 1 and 65536
Users none The users allowed to login to the FTP server
Groups none The groups allowed to login to the FTP server
Log to Tracker false Flag determining whether executions should be logged to the tracker
Document Type 'FTP Server' 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
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

This example demonstrates the invocation of a Gloop when a file is uploaded to its virtually-hosted directory:

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 named VarDump.groovy, which simply prints the available variables in the context:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
[ 
    'file',
    'filename',
    'inputStream',
    'reader',
    'multipartFile',
    'internalId' ].each {

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

Setting up an FTP server on package named ftpServerDemo gives us the following directory structure:

1
2
3
4
5
6
7
.
└── packages
    └── ftpServerDemo
        └── java-VarDump
            ├── <ommitted>
            ├── ...
            └── public java.lang.Object io.toro.integrate.core.service.GenericServiceObjectWrapper.main(java.util.Map)

Wrapped Scripts

Since groovy scripts aren't really classes, TORO Integrate wraps these files into a GenericServiceObjectWrapper using the method main as entry point.

When the endpoint is triggered - in this case, the file hello.txt being uploaded to /packages/ftpServerDemo/groovy-VarDump/...main(java.util.Map) (name shortened for brevity) - the console prints accordingly:

1
2
3
4
5
6
file     : <long path>/hello.txt
filename     : <long path/hello.txt
inputStream  : java.io.FileInputStream@65241d4c
reader   : java.io.InputStreamReader@38299aa6
multipartFile    : io.toro.integrate.core.util.ESBMockMultipartFile@30b7ae2b
internalId   : 1ea5dd9c-a584-473a-b3fb-addb50754511

This also produces a file in the same directory called hello.txt-output.

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
class FileExample {

    public String logContents( File file, String content ) {
        return "Got '${file}', containing '${content}'"
    }
}

This loads the content of the file to the variable content. When served over FTP, this produces following directory structure:

1
2
3
4
5
6
7
.
└── packages
    └── ftpServerDemo
        └── java-FileExample
            ├── <ommitted>
            ├── ...
            └── public java.lang.String FileExamples.logContents(java.io.File,java.lang.String)

Uploading a file called map.txt to that directory invokes the #logContents method, and produces a file called map.txt-output. The content of this output file (possibly) will be:

1
Got 'map.txt', containing 'x marks the spot'

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.