A small, dependency-light WebDAV server written in Go. It serves a local
directory over HTTP using the WebDAV protocol, so it can be mounted by Finder,
Windows Explorer, davfs2, rclone, and other WebDAV clients. It
supports optional HTTP basic authentication and graceful shutdown.
- Serves any existing local directory over WebDAV (PROPFIND, MKCOL, COPY, MOVE, LOCK, and related methods).
- Public mode by default, or password protection with a single user.
- Flexible listen address:
host:port,hostalone (port 8000), orportalone (host 0.0.0.0). - Passwords are read from the
PASSWORDenvironment variable, never from command-line arguments, so they do not appear in process listings. - Constant-time credential comparison.
- Graceful shutdown on
SIGINTorSIGTERM. - Build-time version information injected with
-ldflags.
- Go 1.27 or later
make(optional, but recommended)git(optional, used for version metadata)
git clone https://github.com/CodeIter/webdav-server-golang.git
cd webdav-server
make buildThe binary is written to bin/webdav-server. Copy it somewhere on your PATH if you want to use it globally:
sudo install -m 0755 bin/webdav-server /usr/local/bin/go install github.com/example/webdav-server/cmd@latestNote that go install does not inject version metadata, so --version reports dev.
webdav-server [--help|-h] [--version|-v] [--listen|-l=host:port] [--serve|-s=DIR] [--username|-u=USERNAME]
| Flag | Description |
|---|---|
-h, --help |
Show help and exit. |
-v, --version |
Show version, commit, and build date, then exit. |
-l, --listen |
Address to listen on. Default: 0.0.0.0:8000. |
-s, --serve |
Directory to serve. Required, and it must exist. |
-u, --username |
Enable basic auth for this user. The password is read from $PASSWORD. |
8080listens on0.0.0.0:8080.localhostlistens onlocalhost:8000.192.168.1.10:9000listens on that specific host and port.::1listens on[::1]:8000.
Ports must be between 1 and 65535.
Serve the ./data directory on port 8000 without authentication:
webdav-server -s ./dataServe /srv/files on port 9000:
webdav-server --serve /srv/files --listen 9000Require a login for user alice. The password comes from the environment:
PASSWORD='secret' webdav-server -s ./data -u alice -l 0.0.0.0:8443Show the version:
webdav-server --versionPASSWORD: the password for the user given with--username. It is required only when--usernameis set. If--usernameis omitted, this variable is ignored.
0: success, including--helpand--version.1: a runtime error, such as a failure to bind the port.2: invalid arguments or configuration.
Use the URL http://<host>:<port>/ (or https:// if you terminate TLS in front of the server).
- macOS Finder: Go > Connect to Server, then enter the URL.
- Windows Explorer: Map a network drive and enter the URL.
- Linux: Mount with
davfs2, or open the URL in a file manager such as Nautilus or Dolphin. - rclone: Create a remote with type
webdavand vendorother.
When authentication is enabled, enter the username and the password from $PASSWORD.
- Without
--username, anyone who can reach the port can read and write files in the served directory. Bind to127.0.0.1or a private interface if the server should not be public. - Basic auth sends credentials on every request. Run the server behind HTTPS (for example, a reverse proxy such as Caddy or nginx with TLS) when it is reachable from untrusted networks.
- The server does not follow the served directory's boundaries beyond what
golang.org/x/net/webdavenforces. Do not serve directories that contain sensitive files you do not want exposed. - Locks are kept in memory, so they are lost when the server restarts.
The project uses the following layout:
.
├── cmd/ Entry point (main.go)
├── internal/
│ ├── app/ Wiring of configuration, logging, and server
│ ├── config/ Argument parsing, listen address parsing, usage text
│ └── server/ WebDAV handler construction and lifecycle
├── pkg/
│ └── auth/ Reusable HTTP basic auth middleware
├── version/ Build-time version variables
└── Makefile
Common Make targets:
| Target | Purpose |
|---|---|
make fmt |
Format code with gofmt -s and go fmt. |
make vet |
Run go vet. |
make test |
Run tests with the race detector. |
make build |
Build bin/webdav-server with version metadata. |
make run ARGS="..." |
Run from source with the given arguments. |
make clean |
Remove the bin/ directory. |
make all |
Format, vet, test, and build. |
Run the server locally for development:
mkdir -p data
make run ARGS="-s ./data -l 8000"MIT License.