I take this as an opportunity to learn new way of doing this.
Without any technical environment/constraint, here is my guess:
My guess: May or not work
Use FTPClient
FTPFile[] listFiles(
String pathname, FTPFileFilter filter)
Version of listFiles(String) which allows a filter to be provided.
And implement FTPFileFilter