0

I have a requirement of detecting addition of new files into a folder on a remote Linux server that follows SFTP for its connection.

Right now I am trying to detect the changes from local(windows OS ) by using Java nio Watch service, but it seems it can work for local file changes or shared drive file changes.

I can't post my code due to some genuine reason, but I have used jsch to connect to SFTP server and Java nio Watch service to detect the file changes.

I will be deploying the java springboot app on openshift as a docker container(can jsch and watcher service be used for linux based containers to detect file changes on remote linux SFTP server?).

I went through Google and got few answers but I am confused a bit.

Want to know a better approach to detect the file changes on remote SFTP based Linux server.

Much thanks for the help!!

Adya Jha
  • 1
  • 1
  • 1
    I'm guessing the answer is "Sorry, you can't do that with a FileWatcher", unless you do some trickery to make the SFTP server look like a local volume using something like FUSE. Here's one recommendation: https://stackoverflow.com/a/2142987/611819 – dnault Aug 12 '20 at 20:36
  • Oh okay!, Yah from the link provided I can understand that we need to some tricks from our side, like run a scheduler that would connect to the SFTP server, download the newly added files to the local container(some logic to be implemented for this) and then disconnect, now do the processing on those local files. Or another one is ,rdp4j. – Adya Jha Aug 13 '20 at 07:41
  • Regarding FUSE utility, I am not much aware of but would look into that as well. Thank you! – Adya Jha Aug 13 '20 at 07:42

1 Answers1

1

Checkout the rdp4j library :https://github.com/drapostolos/rdp4j/wiki/User-Guide

PolledDirectory eample to detect changed files: https://github.com/OhadR/rdp4j-client/blob/master/src/main/java/example/sftp/SFtpDirectory.java

As you are using jsch, another (somewhat hacky) option is to simply run a Linux command on the remote server and grab the list of files modified between X and X+n timestamps. You can specify precise timestamps programatically and run it on a schedule (all file "pollers" are basically scheduled jobs that keep checking super frequently)

find /tmp -type f -newermt "2020-08-12 15:01:00" ! -newermt "2020-08-12 15:02:00"

The find command's "newermt" option lets you specify precise timestamp ranges, and you can avoid the guess work that comes with -mmin or -mtime option.

Thyag
  • 1,217
  • 13
  • 14
  • I am required to poll for 24*7 for any file changes, so do i need to use a true while loop with a polling interval of no timeout and never stop the directory poller? Can you please help me in understanding how polling can be done 24*7 if I use above rdp4j approach? Thanks!! – Adya Jha Aug 13 '20 at 08:36