使用傳送定義檔
您可以指定傳送定義檔,它可用來建立檔案傳送。 此傳送定義檔是 XML 檔,它定義建立傳送需要的部分或全部資訊。
當您想要在單一傳送作業中指定多個來源檔案及多個目的地檔案時,傳送定義檔會很有幫助。 您可以使用傳送定義檔來提交複式檔案傳送。 您可以重複使用及共用傳送定義檔。
傳送定義檔可以使用兩種格式,這些格式大同小異,且都符合 FileTransfer.xsd 綱目。 您可以在 WebSphere® MQ Managed File Transfer 安裝的 samples\schema 目錄中找到此綱目。
下列是兩種支援的傳送定義檔格式:
- 傳送的來源和目的地檔案的定義。 此定義使用 <transferSpecifications> 元素作為根元素。
- 整個傳送的定義,包括來源和目的地檔案,以及來源和目的地代理程式。 此定義使用 <request> 元素作為根元素。
- 可以使用 -gt 參數,從 fteCreateTransfer 指令產生具有此格式的檔案。
下列範例顯示的傳送定義檔格式只指定傳送的來源和目的地檔案:
<?xml version="1.0" encoding="UTF-8"?>
<transferSpecifications xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="FileTransfer.xsd">
<item checksumMethod="MD5" mode="text">
<source recursive="false" disposition="leave">
<file>textTransferTest.txt</file>
</source>
<destination type="directory" exist="overwrite">
<file>c:\targetfiles</file>
</destination>
</item>
</transferSpecifications>
若要提交此格式的傳送定義檔,您必須在指令行上指定來源和目的地代理程式:
fteCreateTransfer -sa AGENT1 –sm agent1qm -da AGENT2 –dm agent2qm -td
c:\definitions\example1.xml
下列範例是一個傳送定義檔格式,它指定傳送需要的全部資訊:
<?xml version="1.0" encoding="UTF-8"?>
<request version="3.00" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="FileTransfer.xsd">
<managedTransfer>
<originator>
<hostName>example.com.</hostName>
<userID>fteuser</userID>
</originator>
<sourceAgent agent="AGENT1" QMgr="agent1qm"/>
<destinationAgent agent="AGENT2" QMgr="agent2qm"/>
<transferSet>
<item mode="binary" checksumMethod="MD5">
<source recursive="false" disposition="leave">
<file>c:\sourcefiles\*.jpg</file>
</source>
<destination type="directory" exist="error">
<file>/targetfiles/images</file>
</destination>
</item>
</transferSet>
</managedTransfer>
</request>
您可以在 fteCreateTransfer 指令上使用 -gt 參數來產生具有此格式的檔案。 當您提交此格式的傳送定義檔時,不需要在指令行上指定任何其他項目:
fteCreateTransfer -td c:\definitions\example2.xml
除了傳送定義檔之外,您還可以傳入一般參數,以置換指令行的來源和目的地代理程式相關資訊。 例如:
fteCreateTransfer -da AGENT9 -dm agent9qm -td c:\definitions\example2.xml
此範例使用指令行選項,將傳送定義檔內定義的目的地代理程式置換成 AGENT9,並將傳送定義檔內定義的目的地佇列管理程式置換成 agent9qm。
上述兩種格式都包含一個以上的 <item> 元素。 For further information about the <item> element, see 檔案傳送要求訊息格式. 這些傳送項目各自定義一對來源和目的地檔案,以及控制傳送行為的其他屬性。 例如,您可以指定下列行為:
- 傳送是否使用總和檢查
- 傳送是文字還是二進位
- 傳送完成之後是否刪除來源檔案
- 是否改寫目的地檔案(如果該檔案存在的話)
使用傳送定義檔的優點是,您可以指定指令行無法提供的其他選項。 例如,當您執行「訊息至檔案」的傳送時,可使用傳送定義檔來指定 groupId 屬性。 此屬性指定從佇列讀取之訊息的 IBM® WebSphere MQ 群組 ID。 傳送定義檔的另一個優點是,您可以為每一對檔案指定不同的選項。 例如,您可以指定是否使用總和檢查,或者是以文字模式還是以二進位模式逐一傳送檔案。 如果您使用指令行,則每一個傳送檔案都套用相同的選項。
例如:
<item checksumMethod="none" mode="binary">
<source disposition="leave">
<file>c:\sourcefiles\source1.doc</file>
</source>
<destination type="file" exist="error">
<file>c:\destinationfiles\destination1.doc</file>
</destination>
</item>
<item checksumMethod="MD5" mode="text">
<source disposition="delete">
<file>c:\sourcefiles\source2.txt</file>
</source>
<destination type="file" exist="overwrite">
<file encoding="UTF8" EOL="CRLF">c:\destinationfiles\destination2.txt</file>
</destination>
</item>
<item checksumMethod="none" mode="text">
<source recursive="false" disposition="leave">
<file>c:\originfiles\source3.txt</file>
</source>
<destination type="file" exist="overwrite">
<file>c:\targetfiles\destination3.txt</file>
</destination>
</item>