
Have a look at the inotify man page for description of the various events. So you could setup a Incron entry that would monitor your SFTP upload directories, and any time a specific file event is detected, copy the file. Where Cron works based on time, Incron works based on file events. There is a service called Incron which works similarly to Cron.

You could make use of Inotify events that the Linux kernel produces every time a file is accessed. You could also make use of syslog, which could monitor for the "CLOSE" log events and it could be used to perform the copying of the transferred files. These represent a completed file transfer. You would then need to develop a daemon/script that would monitor the logs for the open/close event pairs. Sep 16 16:07:54 localhost sftp-server: session closed for local user sftp1 from Sep 16 16:07:51 localhost sftp-server: close "/home/sftp1/transactions.xml" bytes read 0 written 192062308 Sep 16 16:07:46 localhost sftp-server: open "/home/sftp1/transactions.xml" flags WRITE,CREATE,TRUNCATE mode 0644 Sep 16 16:07:40 localhost sftp-server: closedir "/home/sftp1" Sep 16 16:07:40 localhost sftp-server: opendir "/home/sftp1" Sep 16 16:07:19 localhost sftp-server: session opened for local user sftp1 from The SFTP logs can be enhanced so they look like this: Sep 16 16:07:19 localhost sftpd-wrapper: user sftp1 session start from 172.16.221.1
#PERL FILE MONITOR DETECT FILE CHANGE HOW TO#
Further details on how to achieve this are already partially covered in my answer to this U&L Q&A tiled: Activity Logging Level in SFTP as well as here in this blog post titled: SFTP file transfer session activity logging. You could write a daemon/script that watches these logs and then backs the file up when needed.

If you turn up the debugging of sftp-sever you can get it to show logs of when files are being open/closed and read/written to/from the SFTP server. Overriding the default sftp-server in sshd_config is easy: Subsystem sftp /usr/local/bin/sftp-serverįiguring out what to do in the wrapper script would be the hard part.In /usr/local/bin/sftp-server: #!/bin/shĬhroot /my/secret/stuff /usr/libexec/openssh/sftp-server You could wrap the sftp-server daemon via sshd_config and "override" it with your own script that could then intercept what sftp-server is doing, and then act when you see that a file was downloaded.

There are 3 avenues that I can conceive of that might provide you with a solution.
