Connector Tutorial Scenario 2: Fetch File¶
Fetching a Text File from Dropbox and Writing It to an FTP Server¶
This scenario demonstrates another use of the “Dropbox Fetch File” activity created in Scenario 1: Fetch File. In this example, a text file is fetched from Dropbox and the contents of that text file are accessed and decrypted.
These contents are then written to an FTP server. Unlike Scenario 1, the resulting file is a text file that contains only the content of the file received from Dropbox, without the metadata.
To complete this scenario, you’ll need a text file in the folder of your Dropbox application. A sample file
customers.csv is provided in the
assets/sample-data directory of the Dropbox connector source files for this purpose.
Here is the completed operation:
1. Copy Sample File to Dropbox¶
Copy the sample file (
customers.csv) from the
assets/sample-data directory of the Dropbox connector to your Dropbox account.
2. Add a Dropbox Fetch File Activity to an Operation¶
Add a Dropbox Fetch File activity to a new operation.
As in Scenario 1, you will need a Dropbox Fetch File activity. You can reuse the “Dropbox Fetch File” activity from the first scenario or create a new one.
To reuse the activity from the first scenario, click the Components tab of the project pane on the left. From there, you can drag the existing Dropbox activity to a new operation.
3. Add a Transformation to the Operation¶
Add a transformation after the “Dropbox Fetch File” activity.
Edit the transformation, but unlike Scenario 1, create a new flat schema (Define Schema > Create Flat) with two string fields: a
name field and a
Once created, you can use the Automap Exact Matches link to map the source fields to the target fields.
4. Edit the Target Field Mappings¶
Edit the script on each target field to write the name and content to global variables, then report the global variable values in the operation log.
name field, enter this script:
$dropboxName = fetchFileResponse$name$; WriteToOperationLog("Fetched from Dropbox: " + $dropboxName); $dropboxName;
content field, enter this script:
$dropboxContent = String(Base64Decode(fetchFileResponse$content$)); WriteToOperationLog("Decoded Dropbox file content: " + Length($dropboxContent) + " characters"); $dropboxContent;
When the scripts are displayed, they should be similar to this:
name field script takes the name from the “Dropbox Fetch File” response, assigns it to a global variable, writes a message to the operation log, and then sets the name as the value of the field.
content field script takes the content from the “Dropbox Fetch File” response, decodes it from base-64, assigns it to a global variable, writes a message to the operation log, and then sets the content as the value of the field.
These variables are now available to be used to write to the FTP server.
When finished, return to the workflow.
5. Add a Script to the Operation¶
Add a script (the “Vars to FTP Write” script as shown in the completed operation) as an operation step after the transformation. It references the “FTP Write” activity from Scenario 1: Fetch File, as shown below.
Enter as the contents of the script (in Jitterbit Script language):
// Script Vars to FTP Write WriteToOperationLog("Received Dropbox file: " + $dropboxName + " " + Length($dropboxContent) + " characters"); WriteFile("<TAG>activity:ftp/FTP/ftp_write/Write</TAG>", $dropboxContent, $dropboxName); FlushFile("<TAG>activity:ftp/FTP/ftp_write/Write</TAG>"); WriteToOperationLog("Wrote Dropbox file: " + $dropboxName);
FTP used in the above code fragment must match the name of the FTP connection and
Write must match the name of the FTP Write activity used in Scenario 1: Fetch File in order to reuse it.
Close the script to return to the workflow.
6. Run the Operation¶
Deploy and run the operation. If successful, you will see a file created at the FTP server with the same name and contents as that of the file fetched from Dropbox. Appropriate messages will be written to the operation log: