Using sftp outbound gateway to list files from remote directory

I am trying to do what I think is relatively simple and straightforward. I am trying to get a list of files from a specific remote directory and then figure out what I want to do with the files based on date.

The problem I am facing is that as soon as the sftp connection is made and the ls command is executed, it seems to always return files from the root directory "/" instead of navigating to the remote directory I specified, I tried various iterations of the remote directory and / or expressions to get files from a directory that I don't need.

I want to get files from a remote directory: "/ sites / cmsftp / site / live / ftp / cmsoss / outbound"

Configuration:

<int-sftp:outbound-gateway id="remoteftpLS"
                           session-factory="dealerDataSftpSessionFactory"
                           request-channel="sftpRequestChannel"
                           command="ls"
                           remote-file-separator="/"
                           remote-directory="/sites/cmsftp/site/live/ftp/cmsoss/outbound"
                           expression="''"
                           charset="UTF-8"
                           local-directory="${ftpOutputPath}"
                           reply-channel="fileListSplitterInputChannel" />

      

I've also tried:

<int-sftp:outbound-gateway id="remoteftpLS"
                           session-factory="dealerDataSftpSessionFactory"
                           request-channel="sftpRequestChannel"
                           command="ls"
                           remote-file-separator="/"
                           remote-directory="/sites/cmsftp/site/live/ftp/cmsoss/outbound"
                           expression="payload"
                           charset="UTF-8"
                           local-directory="${ftpOutputPath}"
                           reply-channel="fileListSplitterInputChannel" />

      

There are no mistakes here. The first way I found that it was always going to run was when I put in an expression to search for files with a specific name and noticed that I got an exception stating that there was no such file. Only then did I replace the expression with a payload, or "'", which returned me a list of files from the root directory. Stopping at a breakpoint on a custom splitter downstream of that gateway is how I verified that it pulls files from the root directory.

Am I missing something obvious?

+3


source to share


2 answers


you can use gateway
For example:

package org.springframework.integration.samples.ftp; // sample
/**
 * @author Gary Russell
 * @since 2.1
 *
 */
public interface ToFtpFlowGateway {
    public List<Boolean> lsGetAndRmFiles(String dir);
}

      

and in the xml file:

<int:gateway id="gw" service-interface="org.springframework.integration.samples.ftp.ToFtpFlowGateway"
        default-request-channel="sftpRequestChannel"/>

      



and finally:

List<Boolean> results = toFtpFlow.lsGetAndRmFiles("/sites/cmsftp/site/live/ftp/cmsoss/outbound");

      

see ftp example

+1


source


Try the following:

<int-sftp:outbound-gateway id="remoteftpLS"
                       session-factory="dealerDataSftpSessionFactory"
                       request-channel="sftpRequestChannel"
                       command="ls"
                       remote-file-separator="/"
                       expression="'/sites/cmsftp/site/live/ftp/cmsoss/outbound'"
                       charset="UTF-8"
                       local-directory="${ftpOutputPath}"
                       reply-channel="fileListSplitterInputChannel" />

      



From the reference manual:

For all PATH commands the command affects, it is provided with the "expression" property of the gateway. For the mget command, the expression can evaluate to '', that is, retrieve all files or "somedirectory /" and so on.

+1


source







All Articles