Repository navigation
Open
Labels
enhancementNew features or improvements of some kind, as opposed to a problem (bug)
Description
Configurable commands or scripts to run at various point in a file life cycle.
First: You did a great job! Thanks a lot!
Feature-Request: Pre and Post commands What does it means?
Why?
- Encrypt data
- Notify users
- check for requirements
- ...
Pull
-
Global Pre-Pull--Command
- Runs before downloading the sync
- runs for each share not overwritting it
- label:
- %share-path%
- %remote-device-id%
- %local-device-id%
- ...
-
Share Pre-Pull--Command
- Runs before downloading the sync
- only a single share
- label like Global
-
Global Pull-File-Command
- only at download
- run it on each single file
- runing on every share (if not overwritten in the share-setting)
-
Share Pull-File-Command
- only at download
- run it on each single file
- runing only on a single share (overwrittes global-setting)
-
Global Post-Pull-Command
- Runs after downloading the sync
- runing on every share (if not overwritten in the share-setting)
- runs for each share not overwritting it
- label like Global-Pre-Pull
-
Share Post-Pull--Command
- Runs after downloading the sync
- only a single share
- label like Global-Pre-Pull
Push
-
Global Post-Push--Command
- Runs before uploading the sync
- runs for each share not overwritting it
- label:
- %share-path%
- %remote-device-id%
- %local-device-id%
- ...
-
Share Pre-Push--Command
- Runs before uploading the sync
- only a single share
- label like Global
-
Global / Share Push-File-Command
- only at upload
- run it on each single file
- runing on every share
-
Global Post-Push-Command
- Runs after uploading the sync
- runing on every share (if not overwritten in the share-setting)
- runs for each share not overwritting it
- label like Global-Pre-Pull
-
Share Post-Push--Command
- Runs after uploading the sync
- only a single share
- label like Global-Pre-Pull
By default show global setting in share tab
- if values is changed, take the changed value and copy all others
- important, as you do not know, whats is happening in the single shares if changing global settings
- global setting can also used by set the value to
<global> - setting a value to "
" (empty string) means to do nothing! Do not use global setting!
For all:
- some labels like "%filename%", "%input-file%" = input file, %output-file% = ouput file name, "%hash%", %size%" = file size input file, ...
- For using as
myScriptDoingThinks --filname "%filename%" --hash %hash% --size %size% --ouput %output-file%- the client will replace all "%...%" with its values
- if for example %output-file% is not set, file "%input-file% will be uploaded, if it is set file %output-file%
- For using as
Labels:
- %additional-files% = if exist, push also files in each line
<filename>.sha3\n<filename>.meta - %filename% = filename no path
- %input-file% = filename read with absolute path
- %output-file% = filename write with absolute path (if not exist use %input-file%)
- %size% = file size input
- %hash% = hash of the block
- %device-id-local% = client id
- %device-id-remote% = id of extern partner(s)
- %email% = if support of user variables is insert so settings can take by the scripts like email
- %...%
Exit codes
- 0 = OK
- 1 = skip file
- 2 = about sync
Samples
Samples for Pre-Pull-Commands
- Mounting a device
- Checking for internet connection
- Checking for free space / existing file / ...
- Stopping a service using the shared files
- connect to vpn
Samples for Pull-File-Command
- Decrypt file
- check checksum of file
- unzip archivs
- unzip file
- run virus scan
- add data to a database, log, ...
Samples for Post-Pull-Commands
- check checksum of all file
- run virus scan
- send a notification to the user (popup)
- send a email notification
- disconnect from vpn
- run a deploy (e.g. copy to /var/www)
- run a backup
Samples for Pre-Push-Commands
- generate checksum of all file
- Checking for internet connection
- connect to vpn
Samples for Pull-Push-Command
- Ecrypt file
- generate checksum of file
- zip file
- add data to a database, log, ...
Samples for Post-Push-Commands
- Unmounting a device
- disconnect to vpn
- Starting a service again using the shared files
- send a notification to the user (popup)
- send a email notification
Modifikation or addition version of File-Command
- using pipes!
- files is read by the client, gets piped to the command (Standard-Inputstream), doing things on the stream (read, modify, add) and outputs a pipe (Standard-Outputstream)
- Warning: input size may not equal output size (adding cipher header, ...)
- Example (Push):
encrypt-then-hash --hash %hash% --size %size% --device-id %device-id% -file-list %additional-files%- Opens file stream to local source file
- Script
1. Compares stream matching %hash%
2. Encrypts stream and signing it with cert of %device-id%
3. Generate a sha3-hash of the stream
4. output stream - pipe stream data to extern partners
Final
Many information, some complexity but would to a design, where you can do crazy things.
Reacted by Pazuu, Tstassin, Mohamed Ashraf (سعدني), Dmitry Gorohov, Florian Wendelborn, Petko Dichev, A_D, Dimitri Pappas, hubald, L and 43 more
Reacted by bademux, Dmitry Gorohov, awandepan, L, kwuerl, Daniel de Souza, EsEnZeT, anarcat, anthonymaers, Marco Breiter and 6 more
Reacted by ⁂ Tommi
Metadata
Metadata
Assignees
Labels
enhancementNew features or improvements of some kind, as opposed to a problem (bug)

Activity
calmh commentedon Mar 16, 2019
Thanks for a well written feature request. I don't expect this to be implemented in its entirety, but it's a good list to choose from.
[-]Feature-Request: Pre and Post commands[/-][+]Pre and Post commands / hooks[/+]heX16 commentedon Mar 18, 2019
@user9209 "Encrypt data": can the command change the contents of the source file? or creates a copy of the file in another directory with decrypted content?
user9209 commentedon Mar 28, 2019
As description above:
if %output-file% is not use run it in-place (but file size may change!)
if %output-file% is use a new file is used.
The best would be to use pipes (file is read only once from the hdd, all operations are performed and written only once to the hdd)
In-place is not always possible (e.g. output-size > input-size does not work whereas OTR is easy implement in-place).
So it depends on the implementation.
Use as less read and write processes to hdd in the pipeline.
mathematechde commentedon Sep 12, 2019
Would it be possible to implement blocking synchronous scripts on a folder level?
for example 3 folders:
folder a
folder b
folder c
folder b contains copies of your syncthing configuration.
folder a and b contains files with your important data. the scripts within folder a and folder b read the content of folder b.
there are 2 possible outcomes here:
folder a has changed and folder b.
pause syncing of folder a (like litterally and endless loop until... from the script in folder a).
therefore trigger files in folder b are changed and the script in folder a returns. folder a is now synced.
you do not need all of the above stuff to implement all of the above stuff if you can go for blocking a folder sync with scripts.
depends on wether block exchange happens on a folder or global basis. i think.
further example 1, store encrypted files within the syncthing repo
folder e is not added to the syncthing repo
folder c contains the encrypted data, and can be touched by syncthing.
stuff is changed in c, post execute decryption and write it to e
add a hook to whatever you use to create your decrypted files and write to c if there is a change.
crypting stuff can take long, so i would not add that calculation process as overhead to the syncthing scan.
as i wrote within #6009 executing stuff, wich can be changed from the outside world could be a security concern
this feature has to be turned off by default, only accessible with a command line switch
if you depend on it add digital signatures to your files.
danisztls commentedon Jul 21, 2020
Even something simpler would be extremely useful.
Use case:
I have a script that imports pictures from a dir and do all sorts of processing and outputs that to a export dir. Currently I'm using Syncthing to sync both folder from and to my phone. Ideally I would call my script after Syncthing syncs import and call Syncthing to sync back to phone after exporting is done. I could schedule the script execution periodically or monitor for file changes via inotify but processing while Syncthing is syncing may cause conflicts.
desbma commentedon Sep 27, 2022
I have a similar need to run custom commands as "hooks" when certain events happen.
Previously I was using custom inotify scripts but they were unefficient and/or unreliable.
So I wrote a simple daemon to react to Syncthing events using the REST API, and run configurable commands: stfed.
It only supports 3 events (folder down sync finished, file down sync finished, local file conflict), but it works well for my use cases.
I'm posting this here in case this is useful for someone else, if not, its open source, so you can fork and/or complain in issues.
mailinglists35 commentedon Sep 10, 2024
exse2 commentedon May 8, 2025
While people here are writing a diploma thesis on this subject for 5 years by now, I came up with a post script solution which works for all use cases (e.g. big directories where you can't use inotify and such):
andreasscherbaum commentedon May 8, 2025
@exse2 You may want to hide the API key.
This is not a hook, this is a shell script and something needs to run this separate from syncthing. While this solves a problem, it opens other issues, like: what is starting and monitoring this script.
exse2 commentedon May 8, 2025
Thanks, but that's not my real api key. Event, listener, poller, I am pretty sure people in general don't care what you're calling it if it solves this software not having the basic functionality to run something after the sync is done. If you want a proper hook, you can wait, I can't as i'm probably go extinct before it appears if it even does. It has no other issue on Linux, you just wrap it as a systemd service. You know, like syncthing.service itself. No 3rd party needed.