Using FileSystemProvider to Implement an FTP file system

1.7k Views Asked by At

I have developed an app that detects changes in a file system using Java's java.nio.file.WatchService

This works great when setting up a WatchService for the default filesystem:

watchService = FileSystems.getDefault().newWatchService();

The use case I have now is to extend this app to monitor events on a remote ftp server. Specifically, when a new file (ENTRY_CREATE) event is detected get the file and then process it.

Researching this I believe this is the approach:

  1. Implement a custom FTP FileSystemProvider as per NIO.2 documentation
  2. Implement a WatchService implementation for the custom FTP FileSystemProvider

Overall, does this approach look right?

Secondly, any links to tutorials or implementations would be very helpful.

Thanks!

1

There are 1 best solutions below

0
On

Google "Java ftp watchservice" to see what others have done.

For example, see https://github.com/fge/java7-fs-ftp

Note, the watchservice will need to end up polling the remote server. Note also, FTP does not let you get seek into a file (unlike the HTTP range feature), so if someone asks for chunks out of the file in non-sequential order, it won't go smoothly.

You could implement a proxy server and detect changes made by other users of the proxy without polling. Or, if you operate the FTP server site, you could implement an FTP server that ran directly on the remote filesystem and provided notifications.