电竞比分网-中国电竞赛事及体育赛事平台

分享

Mule3.x中對(duì)Ftp協(xié)議的支持

 嶗山道哥 2011-01-12
1.    前言
一直都聽(tīng)說(shuō) Mule 對(duì) Ftp 和 Http 協(xié)議的支持很好,于是就關(guān)注了一下。
Mule 通過(guò)一系列的配置文件的配置就可以完成對(duì) Ftp 服務(wù)器的下載和上傳 ,這個(gè)還是很神奇的。
但是可惜的是, Mule 本身并不支持 FtpS 協(xié)議,只支持 SFTP ,這樣對(duì)于工業(yè)級(jí)的使用上,未免有點(diǎn)不方便 。
 
2.    Mule 3.x 的基本知識(shí)
Mule 是一個(gè)開(kāi)源的 ESB 軟件,基本概念如下:
 
Mule 3.X 中對(duì) Ftp 的支持是通過(guò) < ftp:connector> 等標(biāo)簽實(shí)現(xiàn)的,具體的官方信息如下:
 
在 Mule 3.x 中,運(yùn)行 config.xml 的方法如下:
a.       在 app 目錄下新建一個(gè)目錄,比如 test-ftp
b.       將寫(xiě)好的 config.xml 拷貝到 test-ftp 下,并且取名為 mule-config.xml
c.       在 bin 目錄下,運(yùn)行 CMD 如下
Mule –app test-ftp
 
 
3.    Mule 3.x 中 ftp 支持的方法
a.       從 ftp 服務(wù)器上下載文件的方法
<? xml version = "1.0" encoding = "UTF-8" ?>
      xmlns:xsi = "http://www./2001/XMLSchema-instance"
      xmlns:spring = "http://www./schema/beans"
      xmlns:http = "http://www./schema/mule/http"
      xmlns:vm = "http://www./schema/mule/vm"
      xmlns:ftp = "http://www./schema/mule/ftp"
      xmlns:file = "http://www./schema/mule/file"
      xsi:schemaLocation = "
 
<!--
連接 FTP 服務(wù)器的連接器
-->
    < ftp:connector name = "ftpConnector" binary = "true"
       validateConnections = "true" />
 
 
    < model name = "ftp-model" >
       < service name = "ftp-reader" >
       <!--
     連接 FTP 服務(wù)器的入口節(jié)點(diǎn),在這里配置 ftp 的 ip ,賬戶(hù)和密碼
     利用 file:filename-wildcard -filter 確認(rèn)只下載 xml 文件
     -->
           < inbound >
              < ftp:inbound-endpoint user = "zhany" binary = "true" path = ""
                  password = "zhany" host = "192.168.120.33" port = "21"
                  pollingFrequency = "10000" connector-ref = "ftpConnector"  
                  >
                  < file:filename-wildcard-filter
                     pattern = "*.xml" />
              </ ftp:inbound-endpoint >
           </ inbound >
    <!--
     連接 FTP 服務(wù)器的出口節(jié)點(diǎn),在這里配置地址,將文件下載到 e:/out 目錄下
     同時(shí)利用 outputPattern ,定義下載的文件和源文件同名同類(lèi)型
     -->
           < outbound >
              < pass-through-router >
                  < file:outbound-endpoint path = "/e:/out" outputPattern = "[header:originalFilename]" />
              </ pass-through-router >
           </ outbound >
 
       </ service >
    </ model >
 
</ mule >
 
 
 
b.       上傳文件到 ftp 服務(wù)器上的辦法
<? xml version = "1.0" encoding = "UTF-8" ?>
      xmlns:xsi = "http://www./2001/XMLSchema-instance"
      xmlns:spring = "http://www./schema/beans"
      xmlns:http = "http://www./schema/mule/http"
      xmlns:vm = "http://www./schema/mule/vm"
      xmlns:ftp = "http://www./schema/mule/ftp"
      xmlns:file = "http://www./schema/mule/file"
      xsi:schemaLocation = "
<!--
傳輸文件的連接器
-->
    < file:connector name = "fileConnector" pollingFrequency = "6000" />
<!--
連接 ftp 服務(wù)器的連接器
-->
    < ftp:connector name = "ftpConnector" />
   
    < model name = "model" >
       < service name = "service" >
           < inbound >
           <!--
        利用 fileConnector 讀取 e:/tmp 下的文件
       -->
              < file:inbound-endpoint path = "/e:/tmp"
                  connector-ref = "fileConnector" >
              </ file:inbound-endpoint >
           </ inbound >
           < outbound >
              <!--
        利用 ftpConnector 將文件傳輸?shù)?ftp 服務(wù)器上,這里配置了服務(wù)器的 ip 和賬戶(hù)密碼
       -->
              < pass-through-router >
                  < ftp:outbound-endpoint host = "192.168.120.33"
                     port = "21" user = "zhany" password = "zhany" path = "" connector-ref = "ftpConnector" />
              </ pass-through-router >
           </ outbound >
       </ service >
    </ model >
</ mule >
 
 

本文來(lái)自CSDN博客,轉(zhuǎn)載請(qǐng)標(biāo)明出處:http://blog.csdn.net/nanjingjiangbiao/archive/2010/10/11/5933923.aspx

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶(hù)發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買(mǎi)等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶(hù) 評(píng)論公約

    類(lèi)似文章 更多