Writing a file to a remote FTP, FTPS, or SFTP server
Use a FileOutput node to write a file to a directory on a remote FTP, FTPS, or SFTP server.
Before you begin
These instructions assume that you are using a Windows system, and that you have already created a message flow containing a FileOutput node. You also require the following resources:
- An FTP or SFTP server. Ensure
that an FTP or SFTP server exists
with the following settings, so that you can follow this example scenario:
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 when you follow the instructions in this 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:mqsisetdbparms -w 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.
- The following messages, which must be produced by the message
flow preceding the FileOutput node:
- Three input messages. These messages are sent, in this order,
to the In terminal of the FileOutput node:
- Message 1:
<Message>test1</Message>
- Message 2:
<Message>testtwo</Message>
- Message 3:
<Message>testthree</Message>
<Message>...</Message>
- Message 1:
- A final message sent to the Finish File terminal of the FileOutput node after the first
three messages have been sent:
<thiscanbe>anything</thiscanbe>
- Three input messages. These messages are sent, in this order,
to the In terminal of the FileOutput node:
Procedure
Results
- The file is processed. The FileOutput node generates one
record per message with a local file system line terminator after
each one. The file contains the following data, with each line terminated
by a carriage return (X'0D') and line feed (X'0A') pair of characters
(on a Windows system):
<Message>test1</Message> <Message>testtwo</Message> <Message>testthree</Message>
- Records are accumulated in file test_output1.xml in the C:\FileOutput\TestDir\mqsitransit directory. When the final message is sent to the Finish File terminal, the file is moved to the remote FTP or SFTP server directory (because the Remote transfer property is selected). As a result, the file /ftpfileoutput/test_output1.xml is created.
- If a file with the same name exists in the remote FTP or SFTP server directory, the existing
file is overwritten.
If the remote FTP or FTPS server is not running on a Windows system and the Transfer mode property is set to ASCII, the character encoding and line terminator characters might be modified after transfer. For example, on a z/OS® FTP server, the ASCII text is typically converted to EBCDIC, and the line terminator character pairs are replaced by EBCDIC new line characters (X'15'). Other FTP or FTPS servers might treat ASCII transfers differently. If you are using SFTP, the Transfer mode property is ignored and files are sent as Binary files.
- Because the Retain local file
after transfer property is selected, the local file is not
deleted but is moved from the mqsitransit subdirectory
to the output directory, C:\FileOutput\TestDir.
If a file with the same name exists in the output directory, the existing
file is renamed and moved to the mqsiarchive directory.
For example, the following file might be created: C:\FileOutput\TestDir\mqsiarchive\20081124_155346_312030_test_output1.xmlHowever, if a file with this name exists in this archive directory, it is overwritten according to the value of the Replace duplicate archive files property set on the FileOutput node.