Announcement Announcement Module
Collapse
No announcement yet.
How to upload multiple files to FTP Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to upload multiple files to FTP

    Hi,

    I want to upload files to FTP using SI.
    There may be more than one file.
    Currently i am using this approach:
    Code:
    for(File fileToBeUploaded:filesList)
    	{
    		Message<File> fileMessage = MessageBuilder.withPayload(fileToBeUploaded).build();
    		ftpChannel.send(fileMessage);
    	}
    This way the FTP channel copies the file to my FTP.
    Cant i send a List?
    Tried using this:
    Code:
    Message<List<File>> fileMessage = MessageBuilder.withPayload(filesList).build();
    ftpChannel.send(fileMessage);
    But gave the following error:
    Code:
    org.springframework.integration.MessageDeliveryException: Failed to create sendable file.
    	at org.springframework.integration.file.remote.handler.FileTransferringMessageHandler.redeemForStorableFile(FileTransferringMessageHandler.java:195)
    	at org.springframework.integration.file.remote.handler.FileTransferringMessageHandler.handleMessageInternal(FileTransferringMessageHandler.java:126)
    	at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:78)
    	at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:110)
    	at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:97)
    	at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:61)
    	at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:157)
    	at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:128)
    	at com.ftptest.test.FtpTest.main(FtpTest.java:49)
    Caused by: java.lang.IllegalArgumentException: Unsupported payload type. The only supported payloads are java.io.File, java.lang.String, and byte[]
    	at org.springframework.integration.file.remote.handler.FileTransferringMessageHandler.redeemForStorableFile(FileTransferringMessageHandler.java:189)
    Please help.
    Thanks in advance.
    Regards,
    Annuk

  • #2
    Just add a <splitter/> component to the flow

    Code:
    <splitter input-channel="in" outpur-channel="toFTP"/>
    By default, a <splitter/> will split a payload of Collection<SomeObject> to a set of messages, each containing a payload of SomeObject. So, a list of files will be split into messages, each containing a File from the List.

    Comment


    • #3
      Hey Gary,

      Tried adding the splitter and it worked.
      Thanks for your quick reply.

      Regards,
      Annuk

      Comment


      • #4
        Hi,
        I am uploading files using SI FTP.
        It is a two step process.
        1.Upload file using ftp:outbound-channel-adapter
        2.Check if the file is uploaded or not using ftp:outbound-gateway command="ls"
        This process is a scheduled process.

        How do i tell the schedular to start listening to a specific channel?

        <task:scheduled-tasks>
        <task:scheduled ref="ftpService" method="startFTP"
        cron="0 * * * * ?" />
        </task:scheduled-tasks>


        Thanks in advance.
        Regards,
        Annuk.

        Comment


        • #5
          Why not use the FTP inbound adapter instead of a scheduled task?

          Then your cron expression would go into that adapter's poller.

          Comment

          Working...
          X