On your (s)ftp endpoint you can set delete=true
and filter=#ageFilter
where ageFilter is a reference to a custom file filter that only accepts files older than 15 days.
public class AgeFilter<T> implements GenericFileFilter<T> {
@Override
public boolean accept(final GenericFile<T> file) {
long now = System.currentTimeMillis();
long lastModified = file.getLastModified();
return now-lastModified > CUT_OFF_AGE;
}
}
At the end of the route the (s)ftp enpoint will then delete all files selected by this filter.
As an alternative to the file filter you could throw a RuntimeException
in your processor if the file is NOT older than 15 days. This will make your route fail and and will leave the file on the remote server. However, using exceptions for control flow is really not good practice.