This example gets a directory listing from and FTP directory
using the FTP List Files activity, parses the long directory
listing using Flat File Scheme, iterates through the list of files,
based on the properties of each file.
About this task
Based on the properties of each file, one of the following
actions occurs:
To open, view, and learn more about the FTPParseDirListingExample:
Procedure
- Extract the FTPParseDirListingExample project:
- Find the Default Create Path defined in Studio, the
directory that new projects are created in. To view the current Default
Create Path, select from the Studio toolbar menu. The Preferences window
is displayed. The current Default Create Path displays at the end
of the pane. By default, the Default Create Path is located in the
following directory: C:\Documents and Settings\ myLogin\My
Documents Where myLogin represents
your Windows login name.
- Find the FTPParseDirListingExample.zip file that contains
the files that make up the FTPParseDirListingExample project. If you
accepted the defaults during the installation of Studio, this file
is located in the following directory: C:\Program Files\IBM\WebSphere
Cast Iron Studio 3.X\Samples\FTPParseDirListing
- Copy the FTPParseDirListingExample.zip file from the FTPParseDirListing directory
to the Default Create Path directory.
- Extract the contents of FTPParseDirListingExample.zip
file into the Default Create Path directory.
- Open the FTPParseDirListingExample project:
- Select from the Studio toolbar menu.
The Open dialog box is displayed.
- Browse for and open the FTPParseDirListingExample directory.
- Click on the FTPParseDirListingExample.sp3 file and
click Open. The project is displayed.
- In the Project tab, double-click the processBids orchestration.
The processBids orchestration tab displays the activities of
the orchestration, as shown in the following figure:
- Click the Schedule Job activity. Click the Configure task
in the Checklist. During run time, this activity starts an
orchestration job every 5 minutes.
- Click the FTP List Files activity labeled List
Files Full Dir Listing. Click the Configure task
in the Checklist.. This activity gets a long directory listing
of the files in the /input directory on the FTP
Server and returns the listing as one string in the dirListing output
parameter. In this example, the string returned in the directoryListing
output parameter is stored in the fullDirectoryListing string variable.
If the FTP
Endpoint has been configured for the Parse Directory Listing Example,
click Test in the Configure task to
get the directory listing. The List Only Files (NLST) check
box determines if the directory listing contains just the list of
files or a full directory listing. For this example, clear the List
Only Files (NLST) check box.
- Expand the If...Then activity. During run time,
this activity checks the value of the fullDirectoryListing string
variable and if the value is empty, the If path is run and
the orchestration ends. If the fullDirectoryListing string is not
empty, the Else path is run and the orchestration parses the
directory.
- Click the Read Flat File activity. Click the Map
Inputs task in the Checklist. During run time, the long
directory listing created in the FTP List Files activity, is
passed to the Read Flat File activity via the Data input
parameter.
- Click the Map Outputs task in the Checklist.
During run time, the Read Flat File activity parses the directory
string into the repeating node structure displayed in the Map
Outputs task.
- Click the For Each activity. During run time, the For
Each activity iterates through the repeating node structure that
stores the directory listing. Each iteration is equivalent to a singe
file and the properties of that file.
- Click the Map Variables activity. During run time,
the Map Variables activity converts the size of the current
file into a decimal number.
- Click on the If..Then activity. During run time,
the If..Then activity starts the following If..Then branches.
Results
- If the size of the file is equal to 0, the FTP Rename File activity moves the file to the /processFailed directory
and renames the file by adding the ERROR prefix to the file name.
- If the file name contains a string representing one of the approved
supplies (AcmeInc or WidgetRUs), the FTP Rename File activity based on the file name,
moves the file to the appropriate directory either /processAcmeInc or /processWidgetRUs.
- If the file name contains the string representing the Budget Manufacture
supplier, the FTP Delete File activity removes
the file because Budget Manufacture is on the unapproved supplier
list.
- If the file is not processed by any of the three previous conditions,
the Else clause is called and the FTP Rename File activity moves the file to the /processNewCompany directory.
To run the Parse Directory Listing Example, see the procedures
provided in the Configuring
the FTP Endpoint for the Parse Directory Listing Example section.