# Run Grabbit on a server

Run Grabbit without a window on a Windows computer that stays on (a home server,
a spare PC), and send it downloads from your phone or your browser: it downloads them into its
own folders, such as a network share.

It is the same Grabbit as on a desktop: its list, categories, queues, Scheduler, speed limits and
torrents. You control it with the [remote control's page](https://humblef0ol.github.io/grabbit/help/remote-control.html) (from any phone or
computer on your network), the browser extension pointed at it, or its command line.

> **New:** the server mode is new in this version. Please
> [tell us how it goes](https://github.com/HUMBLEF0OL/grabbit/issues).

## Start it

```powershell
grabbit --headless --data C:\mdm-server --downloads D:\Downloads
```

| Flag | Or the variable | What it sets |
|---|---|---|
| `--data <folder>` | `GRABBIT_DATA_DIR` | the list, settings, certificate and paired devices |
| `--downloads <folder>` | `MDM_DOWNLOADS` | where downloads go (each category's folder inside) |
| `--port <number>` | `MDM_REMOTE_PORT` | the remote control's port (8463) |
| `--listen <address>` | `MDM_REMOTE_LISTEN` | where it listens: every local network address unless given |
| `--hosts <names>` | `MDM_REMOTE_HOSTS` | names besides its addresses the page may be opened by |
| | `MDM_REMOTE_URL` | the page's address as you open it, shown with the pairing code |

The remote control is on in this mode (`MDM_REMOTE=off` turns it off). It stops cleanly, saving
its list, when it is stopped (Ctrl+C).

## Pair your phone

It prints the address to open and, while no device is paired, a pairing code with a QR code:

```text
The remote control listens at: https://192.168.1.10:8463/
Its certificate's SHA-256 fingerprint: DE:26:7F:…
No device is paired yet. Open the address (or scan this) and enter the code 1037 1606 …
```

Then pair as [Control Grabbit from your phone](https://humblef0ol.github.io/grabbit/help/remote-control.html#pair-your-phone) says. For another
code, at any time, with the same data folder:

```powershell
$env:GRABBIT_DATA_DIR = "C:\mdm-server"; grabbit-cli pair
```

To open the page by the computer's name (`https://homeserver.local:8463/`), give Grabbit that name:
`--hosts homeserver.local` (several: separated by commas). Other names are refused, so that no
web page can reach Grabbit through a name of its own.

The command line talks to it as to a desktop Grabbit, with the same data folder:
`grabbit-cli status` (once `api on`), `pair`, and adding an address:
`grabbit /d https://example.com/file.zip`.

## Send downloads from your browser

In the browser extension's menu, **Send downloads to → Another Grabbit (a server)**: type the server's address,
open it once in that browser to accept its certificate, then enter a pairing code (`pair`
above). Downloads the extension catches, and **Download with Grabbit** on a link,
then go to the server instead of this computer. The browser's cookies are not sent to the server:
a download that needs you to be signed in to a site stays with this computer.

## What a server doesn't do

- Nothing opens a window: a download that would ask a question (a duplicate, files already
  there) takes the choice set in the settings, or isn't added.
- Don't publish the port on the internet; reach your home network through a VPN instead.
