Abhishek Nayak
Abhishek Nayak

Reputation: 3748

spring sftp read and write in remote without local directory

I know how to read and write from SFTP location with spring-integration-sftp with below configuration:

<bean id="sftpSessionFactory"
    class="org.springframework.integration.sftp.session.DefaultSftpSessionFactory"
    p:host="${host}"
    p:port="${port}"
    p:user="${username}"
    p:password="${password}"
    p:allowUnknownKeys="true" />

<int:channel id="sftpChannel">
    <int:queue />
</int:channel>

<int-sftp:inbound-channel-adapter
    id="sftpInboundAdapter"
    channel="sftpChannel"
    session-factory="sftpSessionFactory"
    remote-directory="${remote.dir}"
    local-directory="${local.dir}"      <-- i don't want
    auto-create-local-directory="false"
    delete-remote-files="false"
    filename-pattern="*.TXT"            <-- how to specify multiple type
    local-filter="acceptOnceFilter">
</int-sftp:inbound-channel-adapter>

<bean id="acceptOnceFilter"
  class="org.springframework.integration.file.filters.AcceptOnceFileListFilter"/>

<int:poller default="true" fixed-rate="1000" max-messages-per-poll="100" />  

<int:service-activator input-channel="sftpChannel" ref="stringHandler" method="handleMessage"/>

<bean id="stringHandler" class="com.core.sftp.StringHandler"/>

I tried by removing the tag local-directory element but spring not allowing to do that, Is there a way to read and write the file without creating it in local directory?

Is there a way to specify multiple file extension types without case sensitive?

Upvotes: 0

Views: 3432

Answers (1)

Gary Russell
Gary Russell

Reputation: 174484

You can use an outbound gateway (get command with -stream option) to get the remote file as an InputStream.

Note that you are responsible for closing the session once you have read the file contents from the stream.

See the documentation here.

For a case-insensitive match on the file inbound adapter, use a regex instead of a simple pattern: filename-regex="(?i).*\.txt".

There's no pattern matching with the outbound gateway; you have to use the ls command to list the files and fetch the ones you want. The sftp sample shows how to do that.

Upvotes: 2

Related Questions