I have set an SFTP server and some triggers that I want to launch when a file is ready.
In case I started before it was finished or in case there was an error with the connection, I write first to a tmp
folder (using SFTP protocol) and once it is copied I move it to a new
folder.
I'm tracking all events in one folder and the other with inotify:
inotifywait -m --format '%:e %f' new
inotifywait -m --format '%:e %f' tmp
The events for writing the file in the tmp folder are:
CREATE newFile
OPEN newFile
ATTRIB newFile
MODIFY newFile
MODIFY newFile
MODIFY newFile
I've noticed that if I move the file from one folder to the other from bash:
mv tmp/newFile new
A MOVE_TO
event is triggered.
In the tmp folder:
CLOSE_WRITE:CLOSE newFile
MOVED_FROM newFile
In the new folder:
MOVED_TO newFile
However, if I move the file with the RENAME method through SFTP it does not. These are all the events triggered:
In the tmp folder:
CLOSE_WRITE:CLOSE newFile
DELETE newFile
In the new folder:
CREATE newFile
OPEN newFile
ACCESS newFile
CLOSE_NOWRITE:CLOSE newFile
Is this part of the protocol of SFTP? Is it possible to move a file in sftp and actually trigger the MOVED_TO event?
This is the implementation for the sftp client that I'm using: https://github.com/mscdex/ssh2-streams/blob/55fd9c36b6dca8dbf0588a1d6f450b85c784dc72/lib/sftp.js I'm using openssh-sftp-server for the server