Skip to content

Dropbox Connector Tutorial Scenario 3: Put File

Reading a Text File from an FTP Server and Putting It to Dropbox

This scenario demonstrates the use of a Dropbox put file activity. In this example, a text file is read from an FTP server and then is put (written) to Dropbox. Like Scenario 2: Fetch File, the file is placed as a text file rather than as an XML file with encoded content and metadata.

For this, you’ll need a text file located in the path / on your FTP server. Any text file will do, or you can use the sample file customers.csv provided in the assets/sample-data directory of the Dropbox connector source files.

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

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. Create a New Workflow

Start with a new workflow in the current project. You can reuse components from the previous scenarios, but a new workflow makes it easier to keep the operations separate.

3. Add a Script to an Operation

Add a script to a new operation. Edit the script, setting its name as “Read FTP to Vars”.

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 base-64 the text 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.

4. Add an FTP Read Activity to the Operation

Using the FTP endpoint called “FTP” you configured for this tutorial (see Tutorial Scenarios in Dropbox Connector Tutorial), drag an FTP read activity to the new operation, after the script.

Configure it as:

  • Name: Enter “Read”
  • Path: Enter a global variable named [ftpPath]
  • Get Files: Enter a global variable named [ftpFilename]

Click Next and then Finished to return to the workflow.

5. Add a Dropbox Put File Activity to the Operation

Drag a Dropbox put file activity from the component palette to the operation after the “FTP Read” activity.

Configure the file name as [dropboxFilename]:

Click Next and then Finished to return to the workflow.

6. Add a Transformation to the Operation

Add a transformation before the “Dropbox Put File” activity.

When the transformation opens, give it a name (such as “Vars to Put”) and add scripts on the path and content target fields to map the global variables dropboxFilepath and dropboxContents to each respective field.

When completed, the mapped target fields should look like this:

7. Run the Operation

Return to the workflow and deploy and run the operation. Once the operation has completed and the file is put 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:

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.

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