我試圖監視任何新添加的文件到ftp服務器,該服務器將目錄映射到正在運行節點應用程序的服務器上的驅動器。問題是它不會爲通過ftp添加的文件註冊任何事件;當通過節點應用程序修改或創建文件時,它們可以很好地拾取。使用nodejs監視目錄 - 未註冊ftp上傳的文件
我目前使用chokidar看目錄和日誌下面的簡單代碼的任何事件:
const watcher = chokidar.watch('./myDir', {
persistent: true,
awaitWriteFinish: {
stabilityThreshold: 2000,
pollInterval: 100
}
});
watcher
.on('add', path => console.log(`File ${path} has been added`))
.on('change', path => console.log(`File ${path} has been changed`));
我已經添加了awaitWriteFinish
選項來嘗試看看它是否將註冊文件的時候從ftp傳輸完成,但沒有喜悅。
有什麼建議嗎?
您是否嘗試過使用本地API來做到這一點? https://nodejs.org/dist/latest-v6.x/docs/api/fs.html#fs_fs_watch_filename_options_listener –
是的,結果相同。我已經讀過,chokadir在註冊fs.watch錯過的活動時更加可靠。 – user1565766