0

I am trying to upload multiple files using SFTP Outbound Gateway. My Java code is like:

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:

<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

JavaGuy
  • 1
  • 1

1 Answers1

1

MPUT sends all the files in a directory; not a list of File.

From the documentation...

mput sends multiple files to the server and supports the following option:

-R - Recursive - send all files (possibly filtered) in the directory and subdirectories

The message payload must be a java.io.File representing a local directory.

...

(my emphasis, it can also be a String referencing a directory).

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.

Community
  • 1
  • 1
Gary Russell
  • 166,535
  • 14
  • 146
  • 179