英文:
Use a file watcher to detect changes on a remote Linux server
问题
我有一个需要检测远程Linux服务器上的文件夹中新增文件的要求,该服务器使用SFTP进行连接。
目前,我正在尝试使用Java nio Watch服务从本地(Windows操作系统)检测更改,但似乎只能用于本地文件更改或共享驱动器文件更改。
由于某些正当理由,我不能发布我的代码,但我已经使用jsch连接到SFTP服务器和Java nio Watch服务来检测文件更改。
我将部署Java Spring Boot应用程序作为Docker容器在Openshift上(是否可以在基于Linux的容器上使用jsch和观察者服务来检测远程Linux SFTP服务器上的文件更改?)。
我查阅了Google并得到了一些答案,但我感到有些困惑。
想知道一种更好的方法来检测远程SFTP基础的Linux服务器上的文件更改。
非常感谢帮助!
英文:
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!!
答案1
得分: 1
Checkout the rdp4j library: https://github.com/drapostolos/rdp4j/wiki/User-Guide
PolledDirectory example 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 programmatically 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 guesswork that comes with -mmin or -mtime option.
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论