如何使用FTP连接器在Anypoint Studio中使用mule上传和下载文件?

问题描述 投票:1回答:2

我尝试使用FTP连接器和FileZilla FTP服务器(xampp)。这是我的流程代码和输出。如果我正在使用SFTP,我将输出“连接被外部主机关闭”。

配置XML:

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:sftp="http://www.mulesoft.org/schema/mule/sftp" xmlns:ftp="http://www.mulesoft.org/schema/mule/ee/ftp" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
    xmlns:spring="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/ee/ftp http://www.mulesoft.org/schema/mule/ee/ftp/current/mule-ftp-ee.xsd
http://www.mulesoft.org/schema/mule/sftp http://www.mulesoft.org/schema/mule/sftp/current/mule-sftp.xsd">
    <file:connector name="FileRead" readFromDirectory="D:\Data\input" autoDelete="false" streaming="true" validateConnections="true" doc:name="File"/>
    <ftp:connector name="FTP" pollingFrequency="1000" validateConnections="true" outputPattern="output.json" doc:name="FTP"/>
    <flow name="ftpFlow">
        <file:inbound-endpoint path="D:\Data\input" connector-ref="FileRead" pollingFrequency="100000" responseTimeout="10000" doc:name="File"/>
        <ftp:outbound-endpoint host="127.0.0.1" port="14147" passive="true" responseTimeout="10000" doc:name="FTP" connector-ref="FTP" outputPattern="output.json" password="kamal" path="/" user="kamal"/>
    </flow>
</mule>

控制台输出:

INFO  2018-03-01 13:00:07,218 [[ftp].FileRead.receiver.01] org.mule.transport.file.FileMessageReceiver: Lock obtained on file: D:\Data\input\example.json
INFO  2018-03-01 13:00:07,300 [[ftp].FTP.dispatcher.01] org.mule.lifecycle.AbstractLifecycleManager: Initialising: 'FTP.dispatcher.145993108'. Object is: FtpMessageDispatcher
INFO  2018-03-01 13:00:07,305 [[ftp].FTP.dispatcher.01] org.mule.lifecycle.AbstractLifecycleManager: Starting: 'FTP.dispatcher.145993108'. Object is: FtpMessageDispatcher
ERROR 2018-03-01 13:01:12,866 [[ftp].FTP.dispatcher.01] org.mule.retry.notifiers.ConnectNotifier: Failed to connect/reconnect: EEFtpConnector
{
  name=FTP
  lifecycle=start
  this=608b1fd2
  numberOfConcurrentTransactedReceivers=4
  createMultipleTransactedReceivers=true
  connected=true
  supportedProtocols=[ftp]
  serviceOverrides=<none>
}
. Root Exception was: Could not parse response code.
Server Reply: FZS
ftp mule anypoint-studio
2个回答
1
投票

File Zilla的侦听端口是21.端口14147是管理端口。


1
投票

使用那里提供的小小groovy脚本。这应该工作。我只是测试了这个并按预期工作。删除可以通过autoDelete属性或fileAge来完成。请告诉我这是否有帮助

<flow name="ftptestFlow">
    <ftp:inbound-endpoint host="hostname" port="port" path="path/filename" user="userid" password="password" responseTimeout="10000" doc:name="FTP"/>
    <set-variable variableName="fileName" value="fileName" doc:name="fileName"/>
    <scripting:component doc:name="getFile">
        <scripting:script engine="Groovy"><![CDATA[new File(flowVars.fileName).getText('UTF-8')]]></scripting:script>
    </scripting:component>
    <file:outbound-endpoint path="path" outputPattern="filename" responseTimeout="10000" doc:name="File"/>
</flow>
© www.soinside.com 2019 - 2024. All rights reserved.