Skip to content

Feature Enhancement : Add prefix or suffix to file name while the file is getting streamed via SFTP #2955

Open

Description

@sahilmalhotra92

Enhancement

I wanted to give a temporary filename to the file placed in remote server while it was getting streamed. I did not have any other option except renaming the file before and after reading the file. It will be very helpful to have a built-in feature to temporary rename file while streaming it.

Gary Russell suggestion to raise issue
https://stackoverflow.com/questions/56470946/add-prefix-or-suffix-to-filename-while-streaming-the-file-using-get-gateway/56478407?noredirect=1#comment99561801_56478407

Code which I tried

     <dependency>
            <groupId>org.springframework.integration</groupId>
            <artifactId>spring-integration-sftp</artifactId>
            <version>5.1.0.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.integration</groupId>
            <artifactId>spring-integration-core</artifactId>
            <version>5.0.6.RELEASE</version>
        </dependency>
Sftp.outboundGateway(sftpSessionFactory(), GET, "payload.remoteDirectory + payload.filename").options(STREAM)

Activity

  1. changed the title [-]Add prefix or suffix to file name while the file is getting streamed via SFTP[/-] [+]Feature Enhancement : Add prefix or suffix to file name while the file is getting streamed via SFTP[/+] on Jun 7, 2019
  2. added this to the 5.2.M3 milestone on Jun 7, 2019
  3. artembilan commented on Jun 10, 2019

    @artembilan
    Member

    I wonder if this is really going to be a robust solution since we just might not have MV permission on that SFTP side, only reading one.

    I would suggest to consider an Idempotent Receiver solution for such a requirement: https://docs.spring.io/spring-integration/docs/current/reference/html/#idempotent-receiver

    This way you won't process the same file again and will have some external tool like Redis to check that file has been processed.

    If you need to release a file in the end after streaming, you are good to remove an entry from the ConcurrentMetadataStore for that processed file.

    Although I might not mind against MV solution if that is pretty simple and really brings enough value over existing approaches.

    Does it make sense?

  4. added
    status: waiting-for-reporter
    on Jun 10, 2019
  5. garyrussell commented on Jun 10, 2019

    @garyrussell
    Contributor

    I think the issue is if there are multiple instances. The rename would prevent a second instance from finding a file that is already being fetched by another instance.

  6. artembilan commented on Jun 10, 2019

    @artembilan
    Member

    Right. Isn't that what we do with distributed MetadataStore in source filters and in the idempotent receiver as well?
    What is the point to fetch the same file in another instance if it has been processed already?

    Also it looks like with the -stream option we don't have a way to to rename file back automatically, unless we are going to abuse .setHeader(IntegrationMessageHeaderAccessor.CLOSEABLE_RESOURCE, session)...

    I'm not against the feature, I just want to see if we indeed need it so strongly over and existing functionality, although I agree that idempotent receiver doesn't sound so obvious and simple here...

  7. garyrussell commented on Jun 10, 2019

    @garyrussell
    Contributor

    @sahilmalhotra92 Can you provide the exact use case for why you need this?

    Also it looks like with the -stream option we don't have a way to to rename file back automatically, unless we are going to abuse .setHeader(IntegrationMessageHeaderAccessor.CLOSEABLE_RESOURCE, session)...

    I don't think it's abuse, that header is defined as a Closeable; there's no reason we can't wrap the session in another Closable.

  8. garyrussell commented on Jun 10, 2019

    @garyrussell
    Contributor

    @sahilmalhotra92 Actually, for "advanced" cases like this, perhaps it would be better to just use the SftpRemoteFileTemplate directly in your code instead of the gateway...

    template.rename(...);
    template.get(pathToFile, inputStream -> ...);
    template.rename(...); // or template.remove(...);

    WDYT?

  9. sahilmalhotra92 commented on Jun 10, 2019

    @sahilmalhotra92
    Author

    @garyrussell Currently I am renaming the file and renaming it once read, it is solving my purpose even. I was thinking it from nice to have feature if it doesn`t increase the overhead. I will surely replace the logic from fetching the file using SftpRemoteFileTemplate instead of the gateway.

  10. sahilmalhotra92 commented on Jun 14, 2019

    @sahilmalhotra92
    Author

    Not sure if I need to close it or leave it like this.

  11. garyrussell commented on Jun 14, 2019

    @garyrussell
    Contributor

    We can leave it open; I will put it on the backlog and we can revisit later if there is demand for it.

  12. added and removed
    status: waiting-for-reporter
    on Jun 14, 2019
  13. modified the milestones: 5.2.M3, Backlog on Jun 14, 2019
  14. artembilan commented on Oct 30, 2019

    @artembilan
    Member
  15. gopibalagala commented on Jun 13, 2020

    @gopibalagala

    Hi Team,

        I want to download the file from SFTP based on filename calling from rest call, is it possible to pick from based on file name? if Yes, please provide some examples. 
    

    Thanks.

  16. artembilan commented on Jun 15, 2020

    @artembilan
    Member

    @gopibalagala ,

    your question is not related to this ticket.

    Please, use StackOverflow for the proper question-answer interaction.

    Nevertheless your goal could be achieved via SftpOutboundGateway and its GET.
    See more info in docs: https://docs.spring.io/spring-integration/docs/current/reference/html/sftp.html#sftp-outbound-gateway

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions