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
- An FTP, FTPS, or SFTP server. Ensure that an FTP, FTPS, or SFTP
server exists, with the following settings:
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 ansftp::
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:
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.<Message>test1</Message> <Message>testtwo</Message> <Message>testthree</Message>
- 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
Results
- 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.
- 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>
- Message 1:
- 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.
- 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.
- 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.