简体   繁体   English

Spring-Integeration SFTP网关用于Mput操作

[英]Spring-Integeration SFTP Gateway for Mput Operation

I am trying to upload multiple files using SFTP Outbound Gateway. 我正在尝试使用SFTP出站网关上传多个文件。 My Java code is like: 我的Java代码如下:

final DirectChannel reqWriteChannel = (DirectChannel) context.getBean("toWriteChannel");
final PollableChannel repWriteChannel = (PollableChannel) context.getBean("fromWriteChannel");

reqWriteChannel.send(MessageBuilder.withPayload(listOfFiles).build());
Message<?> input = repReadChannel.receive(1000);

System.out.println(input);
System.out.println(input.getPayload().toString());

And this is the XML Config: 这是XML Config:

<int:channel id="fromWriteChannel"><int:queue /></int:channel>
<int:channel id="toWriteChannel" />

<int-sftp:outbound-gateway
      id="sftpWriteOnly"
      session-factory="sftpSessionFactory"
      request-channel="toWriteChannel"
      reply-channel="fromWriteChannel"
      command="mput"
      expression="payload"
      remote-directory="/test/mytest/"
      remote-file-separator="X"
      auto-create-directory="true"
      order="1" mput-regex=".*">
</int-sftp:outbound-gateway>

<int:poller default="true" fixed-delay="500"/>

When I pass a single file, the above code works but when I pass list of files, I'm getting the following exception: 当我传递单个文件时,上面的代码有效,但是当我传递文件列表时,出现以下异常:

Caused by: java.lang.IllegalArgumentException: Only File or String payloads allowed for 'mput'
at org.springframework.integration.file.remote.gateway.AbstractRemoteFileOutboundGateway.doMput(AbstractRemoteFileOutboundGateway.java:816)
at org.springframework.integration.file.remote.gateway.AbstractRemoteFileOutboundGateway.handleRequestMessage(AbstractRemoteFileOutboundGateway.java:598)
at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:109)
at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:158)
... 7 more

Any idea how to fix this and upload multiple files? 知道如何解决此问题并上传多个文件吗? Kindly share any complete example. 请分享任何完整的示例。 Thanks 谢谢

MPUT sends all the files in a directory; MPUT将所有文件发送到目录中; not a list of File . 不是File的列表。

From the documentation ... 文档中 ...

mput sends multiple files to the server and supports the following option: mput将多个文件发送到服务器,并支持以下选项:

-R - Recursive - send all files (possibly filtered) in the directory and subdirectories -R - Recursive -发送目录和子目录中的所有文件(可能已过滤)

The message payload must be a java.io.File representing a local directory. 消息有效负载必须是代表本地目录的java.io.File。

... ...

(my emphasis, it can also be a String referencing a directory). (我的重点是,它也可以是引用目录的String)。

If you don't want to send all the files, you can add a filter. 如果您不想发送所有文件,则可以添加一个过滤器。

Feel free to open an 'Improvement' JIRA Issue and we can add support for a collection of File . 随时打开“改进” JIRA问题 ,我们可以添加对File集合的支持。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM