0

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

Gabriel Furstenheim
  • 2,969
  • 30
  • 27
  • It might be useful to run `strace` on the sftp server process while performing one of these rename operations. It would show you what system calls the sftp server is making. – Kenster Feb 08 '19 at 15:11
  • Try to test moving the file with some other SFTP client like WinSCP. Maybe the implementation is doing the RENAME against the standards as it issuing delete, create etc. – Jokkeri Mar 29 '19 at 06:53
  • when i manually make a file, it triggered but when the file is programmatically made it did not trigger – rd_ Aug 17 '19 at 12:48

0 Answers0