There are (at least) 3 techniques to achieve this:
Add a custom FileListFilter<FTPFile>
(that sorts the FTPFile
objects into the order you desire) to the synchronizer.
Use two FTP outbound gateways, one the list (ls) the files, and one to get each file as needed.
Use the FtpRemoteFileTemplate
from within your own code to list and fetch files.
EDIT
Actually, for #1, you would also need a custom FileListFilter<File>
in the local filter to sort the File
objects. Since the local files are emitted as message payloads after the synchronization is complete.
EDIT2 Remote file template example
This just copies the first file in the list, but it should give you what you need...
@SpringBootApplication
public class So49462148Application {
public static void main(String[] args) {
SpringApplication.run(So49462148Application.class, args);
}
@Bean
public ApplicationRunner runner(FtpRemoteFileTemplate template) {
return args -> {
FTPFile[] files = template.list("*.txt");
System.out.println(Arrays.toString(files));
template.get(files[0].getName(), is -> {
File file = new File("/tmp/" + files[0].getName());
FileOutputStream os = new FileOutputStream(file);
FileCopyUtils.copy(is, os);
System.out.println("Copied: " + file.getAbsolutePath());
});
};
}
@Bean
public DefaultFtpSessionFactory sf() {
DefaultFtpSessionFactory sf = new DefaultFtpSessionFactory();
sf.setHost("...");
sf.setUsername("...");
sf.setPassword("...");
return sf;
}
@Bean
public FtpRemoteFileTemplate template(DefaultFtpSessionFactory sf) {
FtpRemoteFileTemplate template = new FtpRemoteFileTemplate(sf);
template.setRemoteDirectoryExpression(new LiteralExpression("foo"));
return template;
}
}