FTP Command Action Example Flow Chart

FTP Command Action Example Flow Chart

The FTP Command Action allows fine grained control of what FTP commands Flux sends to an FTP, SFTP, or FTPS server. A list of commands is specified and executed sequentially, returning a list of each command's response from the server, if any.

The following example will instruct you on how to setup an FTP Command Action that will upload, download, and rename a file. The FTP Command Action always operates from a local machine to the specified FTP, SFTP, or FTPS host.

Viewing the Example Files

Your Flux installation includes a working, pre-constructed version of this example. To load the example file:

  1. Click the "Repository" tab.
  2. Click the "Import" button.

Screen_Shot_2022-03-07_at_3.56.14_PM.png

In the dialog that appears, browse to <Flux Home>/examples/end_users/ftp_command, and select the Ftp Command.ffc file.

When the workflow finishes uploading, select it from the grid to view the workflow in the Designer.

Navigating to the Designer

The Flux Designer will be used to create and execute the example flow chart. To use the Designer, browse to the Operations Console and select the "Designer" tab.

      Screen_Shot_2022-03-07_at_4.00.02_PM.png

Creating Actions

When you visit the Designer, you'll see a blank workspace representing the new workflow. To create the example, we'll start by populating the workflow with a few actions.

To add an action to the flow chart, left-click the action and drag it onto the Designer workspace to add it to the workflow.

Screen_Shot_2022-03-07_at_4.16.01_PM.png

The following table contains the type, category, and quantity of each trigger and action we'll use in this example.

Action Type
Category
Quantity
FTP Command Action File

1

Console Action Core 1
For Each Collection Element Action Flow 1

Once you've added the actions, your workspace will look like this:

Screen_Shot_2022-03-08_at_11.10.37_AM.png

Setting up Flows

Using the image below as a guide, create flows between the actions. To create a flow:

  1. Hover over the action to show a set of 4 blue arrows. 
    Screen_Shot_2022-03-07_at_4.17.43_PM.png
     
  2. Click and hold the left mouse button on the blue arrow of the action you wish to draw the flow from.
  3. Drag your cursor to the action you wish to draw the flow to and release.

Screen_Shot_2022-03-08_at_11.12.04_AM.png

Editing Action Properties

FTP Command Action

Double-click the FTP Command Action to open its action properties panel. Find the commands property — this property will list the commands that the action will execute against the FTP server.

To add new commands, click the "+ FTP Command" button and a new text box will appear, allowing you to enter the command. Add the following commands to the action:

  • lcd C:\<flux installation directory>\examples\end_users\ftp_command
  • put test.txt
  • ls
  • rename test.txt file.txt
  • ls
  • lcd C:\<flux installation directory>\examples\end_users\ftp_command\receive
  • get file.txt

The "lcd" command will change your local working directory to the value you specify. Point it to the directory this example resides in. The "put" command will upload the test.txt file to the FTP server. The "ls" command will provide proof that the put command was successful by listing the test.txt file in the results. The "rename" command will rename the file to file.txt. The "ls" command, issued again, will show in the results that the file was in fact renamed to file.txt. The next "lcd" command changes the local directory in preparation to receive the new file. Finally, the "get" command downloads the newly renamed file back onto the local machine.

When you're done, the editor window will look something like this:
Screen_Shot_2022-03-08_at_11.15.11_AM.png

Next, we will need to set a host for the FTP Command Action to connect to and issue the specified commands. Any FTP, SFTP, or FTPS server you have available that is accessible from the machine you are running Flux on will work for this action. If you do not have a server available you can download a number of different FTP servers from the internet. There are also many sites that allow you to register and use their remote file transfer servers.

Once you have a reachable file transfer server with valid credentials, go into the Flux designer and edit the "Host" action property of the FTP Command Action. Select the type of hose you are connecting to using the drop-down menu under the "Host" heading. Fill in the "Host name", "User Name", and "Password" fields with the appropriate information. You may also modify the "Port" field if the server you are connecting to is not listening on a default port. The figure below shows the "Host" section. 

Screen_Shot_2022-03-08_at_11.17.07_AM.png

 

For Each Collection Element Action

The For Each Collection Element Action will take the returned result from the FTP Command Action and iterate through each response. We need to set the "Loop Index" action property of the For Each Collection Element Action to "response". Do this by double-clicking the For Each Collection Element Action in the canvas and editing the "Loop Index" property. 

Screen_Shot_2022-03-08_at_11.18.19_AM.png

Console Action

Edit the Console Action "Message" action property to read ${response}. This finds the For Each Collection Element Action's value within that loop iteration and uses it as the Console Action's message.

Screen_Shot_2022-03-08_at_11.19.01_AM.png

Editing Flows

Next, we need to add a runtime data map onto the flow out of the FTP Command Action. You can do this by double-clicking the flow out of the FTP Command Action and clicking the "+ Mapping" button under the "Runtime Data Map" heading.

  Screen_Shot_2022-03-08_at_11.21.15_AM.png

This will bring up the runtime data map editor.  Make sure the source type is from the "Flow Context Source" and the target type is from the "Action Property Target". Next edit the "Source Value" field of the source data map to read "result.result" and the target "Target Name" field to use the "Collection" property. The figure below illustrates the runtime data map.

       Screen_Shot_2022-03-08_at_11.23.08_AM.png

With that change, the flow chart is complete and ready to export to the engine.

 

Running the Flow Chart

Next, export your flow chart to the engine. This can be accomplished by hovering your mouse over the "Workflow" button near the top left of your screen, then clicking the "Submit/Execute" button. You can also use the keyboard shortcut, Ctrl+E. 

Screen_Shot_2022-03-08_at_9.17.25_AM.png

 

A confirmation window will appear if the job was successfully exported. If there is an error message, look over this example carefully, and correct any mistakes made.

 

If you look at your engine's console, you should see the listing from your server showing the uploaded, then renamed file on two separate lines (along with any other files present in the user's home directory when the example was run).

Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.