See information about the latest product version
Reading a file on a remote FTP or SFTP directory
Use a FileInput node to read a file in a directory on a remote FTP or SFTP server and then propagate messages that are based on the contents of that file.
- An FTP or SFTP server. Ensure
that an FTP or SFTP server exists,
with the following settings:
- Server
- ftpserver.hursley.abc.com
- Port
- 21 (for FTP) 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 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 for a broker called MyBroker:
mqsisetdbparms MyBroker -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 MyBroker -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 MyBroker -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 security credentials that are used by an broker.
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 or SFTP server is found. Do not put this file in the input directory but, instead, put it in the FTP 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>
Complete the following steps:
- The file test_input1.xml is transferred from the FTP or SFTP server directory (/ftpfileinput) to the local directory (C:\FileInput\TestDir). The file is deleted from the FTP 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.
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.
You can view information about samples only when you use the information center that is integrated with the WebSphere Message Broker Toolkit or the online information center. You can run samples only when you use the information center that is integrated with the WebSphere Message Broker Toolkit.