Accepting Shared Folders in Syncthing Remotely via Command Line
Syncthing is an open-source peer-to-peer file synchronization program that allows users to share and sync files across multiple devices. By default, Syncthing provides a web-based graphical user interface (GUI) to manage and configure the shared folders. However, there might be situations where you want to accept shared folders remotely via the command line without interacting with the GUI.
Prerequisites
To follow this guide, you need to have Syncthing installed on both the local and remote machines. Additionally, you should have SSH access to the remote machine, allowing you to run commands remotely.
Understanding Syncthing's REST API
Syncthing exposes a REST API that allows you to interact with it programmatically. By using this API, you can manage and configure shared folders without using the GUI. The REST API uses HTTP requests to communicate with Syncthing, allowing you to send commands and receive responses in various formats, such as JSON and XML.
Accepting a Shared Folder Remotely
To accept a shared folder remotely, you need to perform the following steps:
- Obtain the ID of the remote device that is sharing the folder.
- Find the ID of the shared folder on the remote device.
- Create a new shared folder on the local device with the same ID as the remote folder.
- Add the remote device's ID to the local folder's allowed devices list.
Obtaining the Remote Device's ID
To obtain the ID of the remote device sharing the folder, you can use the following command:
curl -s http://remote-machine:8384/rest/device/ | jq -r '.deviceID'This command sends an HTTP request to the remote machine's Syncthing API and retrieves the device ID in JSON format. The jq tool is used to parse and extract the device ID.
Finding the Shared Folder's ID
To find the ID of the shared folder on the remote device, you can use the following command:
curl -s http://remote-machine:8384/rest/folder/ | jq -r '.folders[].id'This command retrieves the list of all folders on the remote device and extracts their IDs.
Creating a New Shared Folder on the Local Device
To create a new shared folder on the local device with the same ID as the remote folder, you can use the following command:
syncthing -cmd 'action=addFolder&id={folderID}&label={folderLabel}&reuseExisting=true'Replace {folderID} and {folderLabel} with the actual ID and label of the remote folder.
Adding the Remote Device's ID to the Local Folder's Allowed Devices List
To add the remote device's ID to the local folder's allowed devices list, you can use the following command:
syncthing -cmd 'action=modFolder&id={folderID}&gid={remoteDeviceID}&deviceAllowlistAdd={remoteDeviceID}'Replace {folderID} and {remoteDeviceID} with the actual IDs of the local folder and the remote device, respectively.
- Syncthing provides a REST API to manage and configure shared folders programmatically.
- To accept a shared folder remotely, you need to obtain the remote device's ID, find the shared folder's ID, create a new shared folder on the local device, and add the remote device's ID to the local folder's allowed devices list.
- You can use tools like
curlandjqto interact with Syncthing's REST API and parse the responses.