I am new to the Spring Framework and, indeed, I am learning and using Spring Boot . Recently, in the application I'm developing, I made Quartz Scheduler work, and now I want to integrate with Spring: FTP connection to the server for writing and reading files.
What I want is very simple (since I was able to do this in a previous Java application). I have two Quartz Jobs jobs that are scheduled at different times every day: one of them reads a file from an FTP server, and the other writes a file to an FTP server.
I will tell you in detail what I have developed so far.
@SpringBootApplication
@ImportResource("classpath:ws-config.xml")
@EnableIntegration
@EnableScheduling
public class MyApp extends SpringBootServletInitializer {
@Autowired
private Configuration configuration;
@Bean
public DefaultFtpsSessionFactory myFtpsSessionFactory(){
DefaultFtpsSessionFactory sess = new DefaultFtpsSessionFactory();
Ftp ftp = configuration.getFtp();
sess.setHost(ftp.getServer());
sess.setPort(ftp.getPort());
sess.setUsername(ftp.getUsername());
sess.setPassword(ftp.getPassword());
return sess;
}
}
The following class, which I named it as FtpGateway, is as follows:
@Component
public class FtpGateway {
@Autowired
private DefaultFtpsSessionFactory sess;
public void sendFile(){
}
public void readFile(){
}
}
, . Spring Integration FTP, -, , , sendFile() readFile() , .
- Inbound Channel Adapter ( FTP?), Outbound Channel Adapter ( FTP?) Outbound Gateway ( ?):
Spring Integration FTP/FTPS : , . .
, , .
, - ?
!
EDIT:
@M. Deinum. -, : FTP, poller 5 . , :
@Bean
public FtpInboundFileSynchronizer ftpInboundFileSynchronizer() {
FtpInboundFileSynchronizer fileSynchronizer = new FtpInboundFileSynchronizer(myFtpsSessionFactory());
fileSynchronizer.setDeleteRemoteFiles(false);
fileSynchronizer.setPreserveTimestamp(true);
fileSynchronizer.setRemoteDirectory("/Entrada");
fileSynchronizer.setFilter(new FtpSimplePatternFileListFilter("*.csv"));
return fileSynchronizer;
}
@Bean
@InboundChannelAdapter(channel = "ftpChannel", poller = @Poller(fixedDelay = "5000"))
public MessageSource<File> ftpMessageSource() {
FtpInboundFileSynchronizingMessageSource source = new FtpInboundFileSynchronizingMessageSource(inbound);
source.setLocalDirectory(new File(configuracion.getDirFicherosDescargados()));
source.setAutoCreateLocalDirectory(true);
source.setLocalFilter(new AcceptOnceFileListFilter<File>());
return source;
}
@Bean
@ServiceActivator(inputChannel = "ftpChannel")
public MessageHandler handler() {
return new MessageHandler() {
@Override
public void handleMessage(Message<?> message) throws MessagingException {
Object payload = message.getPayload();
if(payload instanceof File){
File f = (File) payload;
System.out.println(f.getName());
}else{
System.out.println(message.getPayload());
}
}
};
}
, , csv intro "Entrada" , handler() 5 ... - ?