2
스프링 통합을 사용하면 ftp 인바운드 채널 어댑터를 사용하여 재귀 적으로 파일 (하위 폴더의 파일 포함)을 동기화 할 수 있습니까?스프링 통합 ftp 인바운드 채널 어댑터 재귀 동기화
스프링 통합을 사용하면 ftp 인바운드 채널 어댑터를 사용하여 재귀 적으로 파일 (하위 폴더의 파일 포함)을 동기화 할 수 있습니까?스프링 통합 ftp 인바운드 채널 어댑터 재귀 동기화
아니오; 하지만 당신은 ... 아웃 바운드 게이트웨이 재귀 MGET으로 완벽한 원격 디렉토리 트리를 가져올 수
@SpringBootApplication
@IntegrationComponentScan
public class So42324318Application {
public static void main(String[] args) {
ConfigurableApplicationContext context = SpringApplication.run(So42324318Application.class, args);
List<File> files = context.getBean(Gateway.class).fetchFiles("foo/*");
System.out.println(files);
context.close();
}
@MessagingGateway(defaultRequestChannel = "fetchRecursive")
public interface Gateway {
public List<File> fetchFiles(String remoteDir);
}
@Bean
@ServiceActivator(inputChannel = "fetchRecursive")
public FtpOutboundGateway gateway() {
// Create a recursive MGET gateway that gets the remote directory from the payload
FtpOutboundGateway gateway = new FtpOutboundGateway(sessionFactory(), "mget", "payload");
gateway.setOptions("-R");
gateway.setLocalDirectoryExpression(new SpelExpressionParser().parseExpression("#remoteDirectory"));
return gateway;
}
@Bean
public SessionFactory<FTPFile> sessionFactory() {
return new CachingSessionFactory<>(ftpSF());
}
private SessionFactory<FTPFile> ftpSF() {
DefaultFtpSessionFactory sf = new DefaultFtpSessionFactory();
sf.setHost("10.0.0.3");
sf.setUsername("ftptest");
sf.setPassword("ftptest");
sf.setClientMode(FTPClient.PASSIVE_LOCAL_DATA_CONNECTION_MODE);
return sf;
}
}
결과 : 빠른 응답
2017-02-19 09:55:09.351 INFO 61921 --- [ main] o.s.integration.ftp.session.FtpSession : File has been successfully transferred from: foo/bar.tx
2017-02-19 09:55:09.353 INFO 61921 --- [ main] o.s.integration.ftp.session.FtpSession : File has been successfully transferred from: foo/bar.txt
2017-02-19 09:55:09.356 INFO 61921 --- [ main] o.s.integration.ftp.session.FtpSession : File has been successfully transferred from: foo/bar/abc.txt
2017-02-19 09:55:09.358 INFO 61921 --- [ main] o.s.integration.ftp.session.FtpSession : File has been successfully transferred from: foo/baz.txt
2017-02-19 09:55:09.362 INFO 61921 --- [ main] o.s.integration.ftp.session.FtpSession : File has been successfully transferred from: foo/foo/bar/qux.txt
2017-02-19 09:55:09.364 INFO 61921 --- [ main] o.s.integration.ftp.session.FtpSession : File has been successfully transferred from: foo/foo/baz/fiz.txt
[foo/bar.tx, foo/bar.txt, foo/bar/abc.txt, foo/baz.txt, foo/foo/bar/qux.txt, foo/foo/baz/fiz.txt]
감사 @Gary. 귀하의 코드와 나는 디렉토리 계층 구조와 파일을 얻을 수 있습니다. 내가 폴링 및 원격 서버에서 업데이 트되면 파일을 얻을 필요가 어떻게 아웃 바운드 gateway.Basically 나는 로컬 파일을 동기화해야합니다 (와 트리 구조는 손상되지 않은 상태). – user2654631
'FileExistsMode'를 IGNORE로 설정하면 각 MGET은 이전에 가져 오지 않은 새 파일 만 가져옵니다. 5.0 릴리스에는 존재하지만 타임 스탬프가 다른 파일을 다시 가져 오는 [새 모드] (https://github.com/spring-projects/spring-integration/pull/2062)'REPLACE_IF_MODIFIED'가 있습니다 (어제 PR을 만들었습니다). 또 다른 가능한 솔루션은 인바운드 어댑터와 함께 [스마트 폴러] (http://docs.spring.io/spring-integration/reference/html/messaging-channels-section.html#__smart_polling)를 사용하고 원격 폴링이 null을 리턴 할 때 로컬 디렉토리. –