If you are using OpenSSH (or another SFTP server that uses PAM), set up a custom PAM 'session' module that will be triggered whenever the session is opened or closed.
The standard pam_exec.so
can be used for this purpose:
# Skip the next 1 module if the condition fails
session [success=ignore default=1] pam_succeed_if.so quiet user = BatchUpload
session optional pam_exec.so type=close_session /bin/systemctl --no-block start BatchJob.service
(Please don't actually run the entire job directly within the context of PAM. If you have systemd, run your processing "detached" as a systemd service. If you don't have systemd – use Fedora's oddjobd, or have PAM touch
a flag file for a cronjob to see, or post a message to some form of message queue, etc.)
For OpenSSH, as long as you're not using ChrootDirectory
(though in your case you probably are), the SFTP subsystem can be redirected to a wrapper script that runs the real sftp-server
followed by any kind of custom task you want.
Subsystem sftp-server /usr/local/sbin/sftp-server-wrapper.sh
SSH subsystems are just command aliases, running in the user's context without any additional privileges, so the script would need to use sudo/doas in order to use systemctl.