Reading a file on a remote FTP, FTPS, or SFTP directory

Use a FileInput node to read a file in a directory on a remote FTP, FTPS, or SFTP server and then propagate messages that are based on the contents of that file.

Before you begin

This example is an extension of the example described in Using a local file as input for your message flow and it describes how to use a FileInput node in a message flow. The instructions assume that you are using a Windows operating system and that you have created a message flow containing a FileInput node. You also require the following resources:
  • An FTP, FTPS, or SFTP server. Ensure that an FTP, FTPS, or SFTP server exists, with the following settings:
    Server
    ftpserver.hursley.abc.com
    Port
    21 (for FTP or FTPS) or 22 (for SFTP)
    Working directory
    /ftpfileinput
    Userid
    myuserid
    Password
    mypassword

    These values are for the purposes of this example only. If you use other values, record them so that you can set the appropriate values during the task.

  • A security identity. Use the mqsisetdbparms command to define a security identity called myidentity for your user and password details.
    If you want to connect to an FTP or FTPS server, the security identity must have an ftp:: prefix, to enable the file nodes to find the identity definition. For example, use the following command:
        mqsisetdbparms workDir -n ftp::myidentity -u myuserid -p mypassword
    If you want to connect to an SFTP server, the security identity must have an sftp:: prefix, as shown in the following example:
        mqsisetdbparms -w workDir -n sftp::myidentity -u myuserid -p mypassword
    You can also configure a connection to an SFTP server to use public key authentication, by specifying an SSH identity file and pass phrase, instead of a password. For example:
        mqsisetdbparms -w workDir -n sftp::myidentity -u myuserid -i identity_file -r passphrase

    To check what security credentials are already set, use the mqsireportdbparms command; see Checking the password for a resource that is used by an integration server.

    For more information about configuring connections to an SFTP server, see Transferring files securely by using SFTP.

  • An input file. To follow this example scenario, create an input file called test_input1.xml with the following content:
    <Message>test1</Message>
    <Message>testtwo</Message>
    <Message>testthree</Message>
    Each line ends with a line terminator that is suitable for the system on which the FTP, FTPS, or SFTP server is found. Do not put this file in the input directory but, instead, put it in the FTP, FTPS, or SFTP server directory /ftpfileinput.
  • A message set. This example uses a message set called xml1, which uses the XMLNSC parser. Message set xml1 models messages of the following form:
    <Message>...</Message>

About this task

Complete the following steps:

Procedure

  1. Set the required node properties on the FileInput node.
    The following table summarizes the FileInput node properties that you must set, the tab on which they are displayed, whether they are mandatory, and the required values.
    Tab Property Value
    Basic Input directory C:\FileInput\TestDir

    If the input directory does not exist, no files are processed, even if you are processing files over FTP, FTPS, or SFTP.

    File name or pattern test_input1.xml
    Action on successful processing Move to Archive Subdirectory
    Replace duplicate archive files Selected
    Input Message Parsing Message domain XMLNSC
    Message model xml1
    Polling Polling interval 3
    Retry Action on failing file Add Time Stamp and Move to Backout Subdirectory
    Records and Elements Record detection Delimited
    Delimiter DOS or UNIX Line End
    Delimiter type Postfix
    FTP Remote transfer Selected
    Transfer protocol FTP, or SFTP, or FTPS
    Remote server and port ftpserver.hursley.abc.com
    Security identity myidentity
    Server directory /ftpfileinput
    Transfer mode ASCII (for FTP only)
    Scan delay 45
    If you used other values for your FTP, FTPS, or SFTP server resource, enter those values. The settings used here are identical to those used in the example in Using a local file as input for your message flow, except that the Remote transfer property has been selected and there are now properties on the FTP tab. If you clear the Remote transfer property, the node operates as it does in the example in Using a local file as input for your message flow; the properties on the FTP tab remain set but are ignored.
  2. Deploy the message flow to the integration server. See Deploying integration solutions.

Results

The following actions occur when you perform these steps:
  1. The file test_input1.xml is transferred from the FTP, FTPS, or SFTP server directory (/ftpfileinput) to the local directory (C:\FileInput\TestDir). The file is deleted from the FTP, FTPS, or SFTP server directory.
  2. The FileInput node detects records that end with a DOS or UNIX line end and creates a message for each one that it finds, as defined by the properties on the Records and elements tab. The node propagates three messages to the message flow that is attached to the Out terminal:
    • Message 1:
      <Message>test1</Message>
    • Message 2:
      <Message>testtwo</Message>
    • Message 3:
      <Message>testthree</Message>
  3. If a node is attached to the End of Data terminal, the End of Data message is propagated after the last record in the file has been processed.
  4. When processing is complete, the file test_input1.xml is moved to the mqsiarchive subdirectory C:\FileInput\TestDir\mqsiarchive. If a file called test_input1.xml exists in the mqsiarchive subdirectory, it is overwritten.
  5. If the message flow fails, retry processing is attempted according to the values set in the properties of the FileInput node. In this example task, a time stamp is added to the file name and the file is moved to the mqsibackout directory. Here is an example of the path to such a file: C:\FileInput\TestDir\mqsibackout\20070928_150234_171021_test_input1.xml.

    If an error occurs on the FTP side, stating that access is denied, a 0-byte file is created and moved to the mqsibackout directory. A 0-byte file is created in the mqsibackout directory for every FTP attempt that fails.

Because the Remote transfer property is selected, the FTP scan delay of 45 seconds overrides the polling interval of 3 seconds.

What to do next

For more information, see Controlling how files are separated into records, which shows the effects of specifying other combinations of values in the Record detection, Delimiter, and Delimiter type properties of the FileInput node.