TIL: Minimal Go WebDAV server

I had an interesting little conundrum the other day, which was that I needed to help someone access a remote Linux filesystem via Windows Explorer (long story…) but had no direct connectivity, no way to use network filesystems, no way to use VS Code remote editing (I was going through a bastion) nor an SSH client that would do sshfs.

I could, however, set up a TCP tunnel, so my initial reaction was to go and check if there were any single-file servers in , but then I realized that has a perfectly serviceable module and hacked this together:

package main

import (
    "flag"
    "golang.org/x/net/webdav"
    "net/http"
)

func main() {
    var address string
    flag.StringVar(&address, "a", "localhost:8080", "Address to listen to.")
    flag.Parse()

    handler := &webdav.Handler{
        FileSystem: webdav.Dir("."),
        LockSystem: webdav.NewMemLS(),
    }

    http.ListenAndServe(address, handler)
}

With 1.13 (which is what I had at hand), you need to do:

go get golang.org/x/net/webdav
GOOS="linux" GOARCH="amd64" go build -o webdav main.go

So I copied the binary across, typed http://hostname:port into Windows Explorer, and everything worked: uploading large files, creating directories, editing configurations, etc.

Of course I had to tidy up permissions here and there, but overall, it “just worked”.