Step-By-Step Guide to Use FTP to Download Multiple Files from the Directory at Preferred Location

This example shows how to download multiple files from the directory of a  FTP server and save them at a preferred location on your system.

The List Directory FTP action lists all the files available at the intended directory. Post this action, we are going to use a loop activity to filter the directory list based on our requirement and then the Pull FTP action in another loop to download the required files.

 

Prerequisite:

  1. In the Admin menu, add a FTPApps application.
  2. In the Search Properties panel:
    • In the Display Name field, enter a desired name of the FTP server you want to add.
    • In the Server IP field, enter the IP address of the FTPsever.
    • In the Server Port field, enter the port number of the FTP server.
    • In the Transfer Type list, select whether you want to configure FTP server.
  3. Click the (Save Properties) icon to save the application details
    The FTP sever is configured.

 

To automate the process of downloading required files and save them at a particular location:

Create List of Directory Files

  1. Create a new process.
  2. In the Parameter bar, create in arguments, FTPPath, ExcelOutput, and Result for the first FTP Activity that fetches the list of directory files.
    1. In the FTPPath argument, set the FTP directory location from where you want to fetch the list of directory.
    2. In the ExcelOutput argument, set the location of an empty excel file where you want the save the list of directory files.
    3. In the Result argument, the output result of the FTP operations is saved. The results is stored during the runtime only, it is not available once the process execution completes.
  3. From the Canvas Tools panel, add an Application activity to the Flowchart designer on the Canvas.
  4. In the Application Type list, select FTPApps
  5. In the Select An Application list, select the added FTP application.

 

 

  1. Double click the Application activity, drag the FTP Activity and drop inside the Application activity.

 

 

  1. In the Operation Type list, select List Directory.
  2. In the Ftp Directory Path list, select the argument- FTPPath.
  3. In the Excel Output Path list, select the argument- ExcelOutput.
  4. In the Result list, select the argument- Result.
  5. In the Sort by list, select the preferred criteria of sorting the list. You can sort the files based upon their name, date of modification, file size and file type.
  6. In the Sort Type list, select the preferred type of sorting. You can sort the file in the ascending or descending order.
  7. In the Communication Mode list, select Active or Passive depending on how the data connection is established between the client and the server.
  8. In the Transfer Mode list, select Binary or ASCII (Text) depending on the content of the file to be transferred. You can not transfer images file type using ASCII (Text) mode.

Filter the List of Directory Files Based On Required Criteria

  1. Add an Advanced Loop activity below the FTP Activity. This helps us to filter the list of directory files by running through each file name in a loop until the entire list is checked.  We need to pick the intended file name and save it in a separate file. Refer Advanced Loop activity for more details.
  2. Create in arguments, Regex an out argument, ExcelTable of Argument Type- System.Data.DataRowView. These arguments are used to provide input into the Advance Loop Activity, and access the data returned. the list of filtered files in the datatable or excel file configured.
    1. In the Regex argument, set the wildcard based on which you want to filter the files.
    2. In the ExcelTable argument, the list of filtered files is saved.

 

 

  1. In the Loop Type list, select the preferred loop type. For FTP related processes, it is recommended to choose between Excel File and DataTable to avoid creating complexities and errors.
  2. Click the (Settings) icon to configure the loop. The Source Configuration dialog box appears.

 

 

  1. In the Source Table list, select the argument, Result as the list of directory files from where you want you filter required files is saved in this argument.
  2. In the Output list, select the argument, ExcelTable to store the filtered list.
  3. Click Next. The Column Mapping details appear. The details such as the column name, column type and argument type, related to the table that stores the filtered file names are displayed.

 

 

  1. Click Next. The Preview and Filter details appear.

 

 

  1. Expand Filter And Sort and click the (Add filter expression) icon to add the filter expression.
    1. In the Field Name list, select the field name where you want to apply the filter.
    2. In the Operator list, select the filter operator. Available operators are, Like, Equals and Not Equals.
    3. In the Argument Name list, select the wild card argument, Regex.
    4. In the Sort By list, select the sorting criteria if you want to sort the filtered list based on the filed name and the order.
    5. In the No. of Rows list, you can select an argument containing the row number that indicates the row or rows till which the result should be fetched from the Output table generated as part of List Directory operation.
    6. Click Execute to apply the filter and sort criteria. A preview of the filtered list can be seen under the Preview pane.
    7. Click Finish. Once the filter expression is se, the loop validates the filter expression for each record present in the source table containing list of directory files and saves the data in the Output table selected.
  2. To perform the FTP action on the available list of filtered list of directory files, we need to use another loop that runs trough the entire list and downloads the required files.

Iterate FTP action on Filtered List to Download Required Set of Files

To test run the process in Automation Studio and see the process output you can add a WtieLine activity in the flow.

  1. Double click the Advanced Loop activity, and drop the WriteLine activity to convert the data received in the Output table of above loop, into a string. This string stores the result of the Advanced Loop operation that is the filtered file name and perform the FTP action every time the required file name is encountered in this loop.
  2. As an FTP Activity needs to be inside an Application Activity, drag an Application activity and drop below the WriteLine activity.

 

 

  1. Drag the Application activity and drop below the WriteLine activity.
  2. Set the Application Type as FTPApps and select the FTP application in the Select An Application list.
  3. Double click the Application activity and drop the If activity and drop inside it to iterate the FTP operations of downloading the required files.
  4. Create in arguments, Index and Destination. These arguments are used to set the loop through the entire filtered list and save the files in the required location.

 

 

  1. Set the If condition as Index>=0 and increment it by 1 to run through the entire filtered list of directory files saved in the Output table.
  2. If True:
    1. Drop Assign activity. Assign the value of the FTP directory and the filename filtered from the previous loop such as, "\"+ExcelTable.tostring to the FTPath argument.
    2. Drop the FTP Activity and in the Operation Type set the type as Pull.
    3. In the Source File Path list, select the argument, FTPPath.
    4. In the Destination Folder Path list, select the argument, Destination.
    5. Select Communication Mode and Transfer Mode.
  3. If False, exit the loop.

 

 

 

The required files are downloaded, based on the filter criteria provided, at destination folder.