Skip to Content

Connector tutorial scenario 3: Put file

Introduction

This scenario demonstrates the use of a Dropbox Put File activity where a file is read from an FTP server and then is put (written) to Dropbox.

In this scenario, a script first sets global variables with a file path and file name, reading from an FTP server to set a global variable with the file content. The transformation then writes those variables to Dropbox using a Dropbox Put File activity.

Note

Similar to Scenario 2: Fetch file, the file is placed as a text file rather than as an XML file with encoded content and metadata.

Here is the completed operation:

image

Important

To complete this operation and scenario, complete the prerequisite setup required in the Dropbox connector tutorial.

You should have the following:

  • Access to a Dropbox account and FTP server.
  • Configured Dropbox and FTP connectors.
  • Access to assets/sample-data directory of the Dropbox connector repository.

1. Copy sample file to Dropbox

If not already present, copy the sample file (customers.csv) from the assets/sample-data directory of the Dropbox connector to your Dropbox account.

2. Add a script to an operation

Add a script to a new operation. Edit the script, setting its name appropriately.

Set the Jitterbit Script contents as:

<trans>
$ftpPath = "/";
$ftpFilename = "customers.csv";
$ftpContents = ReadFile("<TAG>activity:ftp/FTP/ftp_read/Read</TAG>");

WriteToOperationLog("Read from path " + $ftpPath);
WriteToOperationLog("Read file " + $ftpFilename);
WriteToOperationLog("Read " + Length($ftpContents) + " bytes");

$dropboxPath = $ftpPath;
$dropboxFilename = CVTDate(Now(), "GeneralDate", "yyyy_mm_dd_HH_MM_SS")
    + "_" + $ftpFilename;
$dropboxFilepath = $dropboxPath + $dropboxFilename;
$dropboxContents = Base64Encode($ftpContents);

WriteToOperationLog("DropboxFilename: " + $dropboxFilename);
</trans>

This will read and encode using Base64 the file at /customers.csv from the FTP server. Adjust the variable values as required if your file is at a different location or name.

Close the script to return to the workflow.

3. Add an FTP Read activity to the operation

Drag a FTP Read activity from the design component palette to the component drop zone on the design canvas to create an instance of a FTP Read activity in a new operation. Double-click the activity to open it.

Configure it as:

  • Name: Enter an appropriate identifying name.
  • Path: Enter a global variable named [ftpPath]
  • Get Files: Enter a global variable named [ftpFilename]

image

Click Next and then Finished to return to the workflow.

4. Add a Dropbox Put File activity to the operation

Drag a Dropbox Put File activity type from the component palette to the operation after the FTP Read activity.

Configure the file name as [dropboxFilename] and click Next:

image

Click Finished to return to the workflow:

image

5. Add a transformation to the operation

Add a transformation before the Dropbox Put File activity.

When the transformation opens, give it a name and add scripts to the path and content target fields to map the global variables dropboxFilepath and dropboxContents to each respective field.

Click the Close icon to save the transformation configuration and return to the workflow:

image

6. Run the operation

Return to the workflow and deploy and run the operation. Once the operation has completed and the file is put (written) to Dropbox, you should see log messages such as these in the operation log, with the file successfully copied from the FTP server to Dropbox:

image

Variations

You can modify this example to explore issues that developers of connectors need to consider.

For example, you could set the path field in the transformation to an empty string, and then in the Dropbox Put File activity supply the path using either a hard-coded value or by using a variable already defined ($dropboxPath). This will write the file to the location set by the script.

The code for the Dropbox connector (put-file-request.xsd) requires that the path be defined, as shown by the [1] to the left of the field name in the transformation. However, you could require that it instead be defined in the user interface for the Dropbox Put File activity by configuring the code (adapter.json) that describes the UI.

In the case of the Dropbox connector, the connector code (PutFileActivity.java) is written such that the definition given in the Dropbox Put File activity, if specified, takes precedence over the value that is specified in the transformation.

The approach you use depends on how you intend a connector to be used or configured.