Tutorial: Read Files and Write the Files to File Server

Learn how to use the File server action to read one or more files that are on an FTP server and then write the files to File Server in Oracle Integration.

Audience

This tutorial is most helpful if your organization already uses File Server or is considering using it. That's because the tutorial requires you to enable and set up File Server.

This tutorial is also helpful if you want hands-on practice using the File server action. If you just want step-by-step instructions for using the File server action, see Interact with Files in File Server in Using Integrations in Oracle Integration 3.

Prerequisites

  • Set up an invoke FTP connection to your FTP server, and name it Supplier_FTP.

  • Enable File Server and complete all of the setup steps.

    See Administer File Server in Using File Server in Oracle Integration 3.

  • Place a file on your organization's FTP server so that you can move the file to File Server. Note the file name and its directory.

Step 1. Create a schedule integration and define its trigger

Start by creating a schedule integration. You pass in two parameters for the integration's trigger.

  1. In the navigation pane, click Design, then Integrations.

  2. Select Create.

  3. Select Schedule, and fill in the following field.

    Field Value to use
    Name Poll_For_New_Files
  4. Select Create.

    The integration canvas appears, and a menu of options appears.

  5. Select anywhere on the canvas to close the menu.

  6. On the canvas, point to the Schedule action, select ..., and select Edit.


    On the Schedule box, the … button is selected, and a menu appears. A mouse cursor points to the Edit option in the menu.

  7. Define the parameters for the integration's trigger:

    These parameters let you pass in the file pattern and path of the file you're picking up from your FTP server.

    1. Select +, and fill in the following fields.

      Field Value to use
      Parameter name file_pattern
      Default value "*.csv"
    2. Select +, and fill in the following fields.

      Field Value to use
      Parameter name directory
      Default value "/"
    3. Select Save.

You've created a schedule integration that passes in two parameters.

Step 2. Connect to an FTP server and list the files in a directory

Now that you've created an integration, it's time to add an action to it. The invoke action calls your FTP server and lists all the files in a specific directory. You passed the directory into the integration's schedule when you defined its trigger.

  1. Point to the line that comes out of the Schedule box until a + appears, and select the +.


    A mouse cursor points to the line that comes out of the Schedule box. A plus sign + button appears.

  2. In the search field, type Supplier, and select the Supplier_FTP connection that you created as a prerequisite task.

    An Invoke action appears on the canvas, and the Configure Basic Info panel appears.

  3. Fill in the following fields.

    Field Value to use
    What do you want to call the endpoint? listFiles
    B2B Trading Partner Mode Do not select this checkbox.
  4. Select Continue.

  5. From the Select operation drop-down list, select List Files.

  6. Fill in the following fields.

    Field Value to use
    Input directory /

    This value is a placeholder. Later on, you'll map the scheduled parameter to it. 

    File name pattern *.csv
    Max files Leave the default value.
    Minimum age Leave the default value.
    List File Recursively Deselect this option.
    Ignore File Permissions Leave this option deselected.
  7. Select Continue.

  8. Review the settings, and select Finish.

You finished creating the call to your remote FTP server. The call lists the files in a specific directory.

A Map action appears on the canvas before the Invoke action.


The canvas contains 3 actions: Schedule, Map, and Invoke.

Tip:

To view the actions horizontally on the sanvas, select Horizontal Horizontal layout icon on the toolbar.

Step 3. Pass the folder from the integration's schedule to its invoke action

You've defined the invoke action, and now it's time to dynamically pass the directory into it using the Map action.

  1. On the canvas, point to the Map action, select ..., and select Edit.

    The mapper appears.

  2. In the Sources list on the left, observe the two parameters that you configured: directory and file_pattern.

  3. In the Target list on the right, expand List Request, then expand FTP List Header.

  4. In the Sources list, select directory, and drag it to the Directory entry in the Target list.

  5. In the Sources list, select file_pattern, and drag it to the File Name Pattern entry in the Target list.


    In the mapper, directory is connected to Directory, and file_pattern is connected to File Name Pattern

  6. Select Validate, and then select < to return to the canvas.

  7. Save your changes.

Now you are passing the directory into the invoke action dynamically using the trigger of the integration.

Step 4. Loop through the files and process them one at a time

The integration must loop through all the files that the invoke action returns. The integration processes the files one at a time using a for each action.

  1. Add the for each action to the integration:

    1. Point to the arrow that comes out of the Invoke box, and select +.

    2. In the pop-up, select the Actions tab.

    3. Scroll to and select For each.

      A For each action appears on the canvas, and the Configure for each panel appears.

    4. In the panel, select Edit Edit icon, and fill in the following field.

      Field Value to use
      Name ForEachFileFound
    5. Select Save expression icon.

    6. In the Input sources panel, expand $listFiles, then ListFileResponse, then ListResponse, then FileList, and then File.

      File lists the properties of each file.

    7. Drag the File entry to the Repeating element field.

      File is the element that the for each loop repeats on.

    8. In Current element name, enter currentFileDetails.

      This is the name that the integration uses to refer to the File element in the loop.

    9. Select anywhere in the canvas to close the panel.

  2. Specify how the for each loop processes each file.

    The first action downloads a file.

    1. On the canvas, in the box for the For each action, select +.

    2. In the search field, type Supplier, and select the Supplier_FTP connection that you created as a prerequisite task.

      This connection allows you to make a connection to your FTP server.

    3. Fill in the following fields.

      Field Value to use
      What do you want to call the endpoint? downloadFile
      B2B Trading Partner Mode Leave this option deselected.
    4. Select Continue.

    5. Fill in the following fields.

      Field Value to use
      Select operation Select Download File.
      Select a Transfer Mode Leave Binary selected.
      Input directory Leave this field blank for now. Later on, you'll dynamically populate this field using the mapper.
      File name Leave this field blank for now. Later on, you'll dynamically populate this field using the mapper.
      Download directory /stage/files

      This is the location in Oracle Integration where you'll temporarily store the downloaded file.

      Checkboxes on the page

      Leave all the checkboxes deselected.

    6. Select Continue.

    7. Review the settings, and select Finish.

    You return to the canvas. The Invoke action that you configured appears within the For each action, and a Map action appears before it. The invoke action downloads a file and stores it in a temporary location.


    The canvas contains 4 actions: Schedule, Map, Invoke, and For each. For each contains 2 actions: Map and Invoke.

  3. Pass the relevant data to the Invoke action.

    This action ensures that within the loop, for each file that the integration finds, the integration downloads the file to the local staging area.

    1. Within the For each action, point to the Map action, select ..., and select Edit.

      The mapper opens.

    2. In the Sources list on the left, expand CurrentFileDetails, then expand File.

      The containers hold information about the current file that has been returned from when you collected a list of files in a directory.

    3. In the Target list on the right, expand Download Request.

      This container holds information about the action you defined for downloading the file.

    4. In the Sources list, select Directory, and drag it to the Directory entry in the Target list.

    5. In the Sources list, select Filename, and drag it to the Filename entry in the Target list.


      In the mapper, Directory is connected to Directory, and Filename is connected to Filename

    6. Select Validate, and then select < to return to the canvas.

    7. Save your changes.

Step 5. Write the file to File Server

The for each loop processes the files one at a time. After processing a file, the integration writes the file to File Server.

  1. In the vertical toolbar to the right of the canvas, select Integration actions icon, and find the File server entry.

  2. Drag the File server entry to the + that appears on the Invoke action that is within the For each action.

    This panel offers an alternate way to add actions to an integration.


    A mouse cursor drops an action on the + that is on the Invoke action within the For each box

    A File server action appears in the For each action, and the Configure FS Native Action panel appears.

  3. Fill in the following fields.

    Field Value to use
    What do you want to call your endpoint? writeFileToFileServer
    Select resource Select File.
    Select operation Select Write File.
    Specify an Output Directory /inbound/supplier/invoices

    This is the directory that you want to write the file to in File Server.

    File Name file.txt

    Later on, you'll overwrite this value in the mapper. You'll use the file name that you got when you listed the file names.

  4. Select Continue.

  5. Review the settings, and select Finish.

    You return to the canvas. The File server action that you configured appears within the For each action, and a Map action appears before it. The File server action writes a file to File Server.


    The canvas contains 4 actions: Schedule, Map, Invoke, and For each. For each contains 4 actions: Map, Invoke, Map, and File server.

    Now you need to pass in the name of the file to be written, as well as the file itself, to the File server action.

  6. Pass the relevant data to the File server action.

    1. Point to the Map action that is before the File server action, select ..., and select Edit.

      The mapper opens.

    2. In the Source list on the left, expand downloadFile Response (FTP), then Download File to ICS Response, then Download Response, then ICS Files, then ICS File.

      The elements are the output of the operation to download the file from the FTP server.

    3. In the Target list on the right, expand File Definitions Write Request.

      Its child elements are the properties that the file operation accepts.

    4. In the Sources list, select File Reference, and drag it to the File Reference entry in the Target list.

      You are passing the contents of the file that you downloaded to the staging area to the File server action in the integration.

    5. In the Sources list, below File Reference, expand Properties.

    6. In the Sources list, select Filename, and drag it to the Output File Name entry in the Target list.

      You are passing the name of the file to the File server action.


      In the mapper, File Reference is connected to File Reference, and Filename is connected to Output File Name

    7. Select Validate, then select < to return to the canvas.

The integration retrieves a list of files from an FTP server and writes the files to File Server in Oracle Integration using the File server action.

Step 6. Understand what you've done

Let's review a few key actions in the integration so that you understand the integration that you just designed.

Action Goal
Schedule action You created a schedule integration, which runs on demand or by the clock.
Invoke action The integration's first action is to make a call to your FTP server to list the files in a directory. You specify the directory using the Map action that is before the Invoke action.
For each action The integration loops through the files that are in the list of files that you just got. For each file in the list, the integration performs several actions.
  • Invoke action: The integration downloads the file.
  • File server action: The integration writes the file to File Server.

Learn More

To review all of your options for the File server action, including encrypting and decrypting files, see Interact with Files in File Server in Using Integrations in Oracle Integration 3.