### Connect WebDAV Clients to ESPWebDAV Source: https://context7.com/d-a-v/espwebdav/llms.txt Examples for mounting ESPWebDAV on different operating systems. Ensure the ESPWebDAV server is running and accessible on the network. ```bash # Linux — mount via davfs2 sudo mount -t davfs http://ESPWebDAV.local/ /mnt/esp # Unmount: sudo umount /mnt/esp ``` ```bash # Linux — mount via gvfs/gio (GNOME) gio mount dav://ESPWebDAV.local/ ``` ```bash # macOS — mount from command line mkdir -p /tmp/esp mount_webdav -S -i -v esp8266 http://ESPWebDAV.local/ /tmp/esp && echo OK # Or via Finder: Go > Connect to Server > http://ESPWebDAV.local/ ``` ```bash # Windows — map as network drive (cmd.exe) net use W: \\ESPWebDAV.local\DavWWWRoot # Or via File Explorer: Map Network Drive > http://ESPWebDAV.local/ ``` -------------------------------- ### ESP32 Standalone WebDAV Server Setup Source: https://context7.com/d-a-v/espwebdav/llms.txt Arduino sketch for setting up a standalone WebDAV server on an ESP32. Requires WiFi credentials and uses LITTLEFS for storage. Includes a transfer status callback for monitoring uploads/downloads. ```cpp // ESP32 — Standalone WebDAV server #include #include #include #include #define HOSTNAME "ESPWebDAV" #define STASSID "your-ssid" #define STAPSK "your-password" FS& gfs = LITTLEFS; WiFiServer tcp(80); ESPWebDAV dav; void setup() { Serial.begin(115200); WiFi.persistent(false); WiFi.setHostname(HOSTNAME); WiFi.mode(WIFI_STA); WiFi.begin(STASSID, STAPSK); while (WiFi.status() != WL_CONNECTED) { delay(500); } MDNS.begin(HOSTNAME); LITTLEFS.begin(); tcp.begin(); dav.begin(&tcp, &gfs); dav.setTransferStatusCallback([](const char* name, int percent, bool receive) { Serial.printf("%s '%s': %d%%\n", receive ? "recv" : "send", name, percent); }); Serial.println("WebDAV server started"); } void loop() { dav.handleClient(); } ``` -------------------------------- ### ESPWebDAV::handleClient() Source: https://context7.com/d-a-v/espwebdav/llms.txt Polls the bound WiFiServer for new clients and processes any pending WebDAV request (PROPFIND, GET, PUT, DELETE, MKCOL, COPY, MOVE, LOCK, UNLOCK, OPTIONS, PROPPATCH). Must be called repeatedly in loop(). Supports HTTP/1.1 keep-alive; the connection is held open for up to 5 seconds between requests on the same socket. ```APIDOC ## ESPWebDAV::handleClient() ### Description Polls the bound `WiFiServer` for new clients and processes any pending WebDAV request (PROPFIND, GET, PUT, DELETE, MKCOL, COPY, MOVE, LOCK, UNLOCK, OPTIONS, PROPPATCH). Must be called repeatedly in `loop()`. Supports HTTP/1.1 keep-alive; the connection is held open for up to 5 seconds between requests on the same socket. ### Method `ESPWebDAV::handleClient()` ### Usage This method should be called repeatedly within the main `loop()` function to ensure that incoming WebDAV requests are processed promptly. ### Request Example ```cpp void loop() { MDNS.update(); // keep mDNS alive dav.handleClient(); // handles one full HTTP/WebDAV transaction per call // Safe to do other work between calls, but avoid long blocking delays // to maintain responsive WebDAV performance } ``` ``` -------------------------------- ### setTransferStatusCallback Source: https://context7.com/d-a-v/espwebdav/llms.txt Registers a callback function that is invoked during file upload (PUT) and download (GET) operations to provide progress notifications. The callback receives the filename, completion percentage, and transfer direction. ```APIDOC ## ESPWebDAVCore::setTransferStatusCallback(cb) ### Description Registers a callback invoked during file upload (PUT) and download (GET) operations. The callback receives the filename, a completion percentage (0–100), and a boolean indicating the direction (`true` = receiving/upload, `false` = sending/download). Useful for driving progress indicators, LEDs, or serial logging. ### Parameters - **cb** (function) - The callback function with the signature `void(const char* name, int percent, bool receive)`. ``` -------------------------------- ### Register File Transfer Progress Callback Source: https://context7.com/d-a-v/espwebdav/llms.txt Registers a callback function that is invoked during file upload (PUT) and download (GET) operations. The callback receives the filename, completion percentage, and direction of transfer, useful for progress indicators. ```cpp dav.setTransferStatusCallback([](const char* name, int percent, bool receive) { Serial.printf("%s '%s': %d%%\n", receive ? "Upload" : "Download", name, percent); // Example: drive an LED brightness from transfer progress // analogWrite(LED_PIN, map(percent, 0, 100, 0, 255)); }); // Expected serial output during a 500 KB upload of "firmware.bin": // Upload 'firmware.bin': 0% // Upload 'firmware.bin': 24% // Upload 'firmware.bin': 51% // Upload 'firmware.bin': 78% // Upload 'firmware.bin': 100% ``` -------------------------------- ### ESPWebDAV::begin(WiFiServer* srv, FS* fs) Source: https://context7.com/d-a-v/espwebdav/llms.txt Initializes the WebDAV server in standalone mode, binding it to an existing WiFiServer and a mounted filesystem. This is the primary entry point for the ESPWebDAV class when no other HTTP server is present. Must be called after WiFi is connected and the filesystem is mounted. ```APIDOC ## ESPWebDAV::begin(WiFiServer* srv, FS* fs) ### Description Initializes the WebDAV server in standalone mode, binding it to an existing `WiFiServer` and a mounted filesystem. This is the primary entry point for the `ESPWebDAV` class (which inherits `ESPWebDAVCore`) when no other HTTP server is present. Must be called after WiFi is connected and the filesystem is mounted. ### Method `ESPWebDAV::begin(WiFiServer* srv, FS* fs)` ### Parameters - **srv** (`WiFiServer*`) - A pointer to an initialized `WiFiServer` instance. - **fs** (`FS*`) - A pointer to the mounted filesystem object (e.g., `LittleFS`, `SPIFFS`). ### Request Example ```cpp // ESP8266 — Standalone WebDAV server on port 80 with LittleFS #include #include #include #include #define HOSTNAME "ESPWebDAV" #define STASSID "your-ssid" #define STAPSK "your-password" FS& gfs = LittleFS; WiFiServer tcp(80); ESPWebDAV dav; void setup() { Serial.begin(115200); WiFi.persistent(false); WiFi.hostname(HOSTNAME); WiFi.mode(WIFI_STA); WiFi.begin(STASSID, STAPSK); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.printf("\nConnected, IP: %s\n", WiFi.localIP().toString().c_str()); MDNS.begin(HOSTNAME); LittleFS.begin(); tcp.begin(); // Bind DAV server to TCP listener and filesystem dav.begin(&tcp, &gfs); Serial.println("WebDAV server started"); // Access: http://ESPWebDAV.local/ or \\ESPWebDAV.local\ (Windows) } void loop() { MDNS.update(); dav.handleClient(); // must be called in every loop iteration } ``` ``` -------------------------------- ### Initialize Standalone ESPWebDAV Server Source: https://context7.com/d-a-v/espwebdav/llms.txt Use this for standalone WebDAV server initialization. Ensure WiFi is connected and the filesystem is mounted before calling. This binds the WebDAV server to a WiFiServer instance and a filesystem. ```cpp #include #include #include #include #define HOSTNAME "ESPWebDAV" #define STASSID "your-ssid" #define STAPSK "your-password" FS& gfs = LittleFS; WiFiServer tcp(80); ESPWebDAV dav; void setup() { Serial.begin(115200); WiFi.persistent(false); WiFi.hostname(HOSTNAME); WiFi.mode(WIFI_STA); WiFi.begin(STASSID, STAPSK); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.printf("\nConnected, IP: %s\n", WiFi.localIP().toString().c_str()); MDNS.begin(HOSTNAME); LittleFS.begin(); tcp.begin(); // Bind DAV server to TCP listener and filesystem dav.begin(&tcp, &gfs); Serial.println("WebDAV server started"); // Access: http://ESPWebDAV.local/ or \\ESPWebDAV.local\ (Windows) } void loop() { MDNS.update(); dav.handleClient(); // must be called in every loop iteration } ``` -------------------------------- ### Configure DAV and Filesystem Roots for Path Remapping Source: https://context7.com/d-a-v/espwebdav/llms.txt Configures the WebDAV URL root and the corresponding filesystem root independently, decoupling the WebDAV namespace from the filesystem layout. `setDAVRoot` sets the URL prefix, and `setFsRoot` sets the filesystem directory where files are stored. ```cpp // Manual configuration equivalent to: // hookWebDAVForWebserver("/files", dav, "/storage") dav.begin(&gfs); dav.setDAVRoot("/files"); // WebDAV responds to URLs starting with /files dav.setFsRoot("/storage"); // Files are stored under /storage on the FS // Result: // DAV URL: http://device/files/report.csv // FS path: /storage/report.csv ``` -------------------------------- ### Initialize ESPWebDAV Core for Shared Port Source: https://context7.com/d-a-v/espwebdav/llms.txt Use this for initializing the WebDAV protocol engine when integrating with an existing web server. It does not use a dedicated server socket. The hosting web server provides the transport. ```cpp #include #include #include FS& gfs = LittleFS; ESP8266WebServer server(80); ESPWebDAVCore dav; // Core only — no dedicated WiFiServer void setup() { // ...WiFi setup... LittleFS.begin(); LittleFS.mkdir("/dav"); dav.begin(&gfs); // Initialize core with filesystem only // Hook WebDAV into the web server (see hookWebDAVForWebserver below) server.addHook(hookWebDAVForWebserver("/dav", dav)); server.begin(); } ``` -------------------------------- ### ESPWebDAVCore::begin(FS* fs) Source: https://context7.com/d-a-v/espwebdav/llms.txt Initializes the WebDAV protocol engine without a dedicated server socket. Used when integrating WebDAV into an existing ESP8266WebServer or WebServer instance via the hook API. The ESPWebDAVCore base class handles all protocol logic; the transport is provided by the hosting web server. ```APIDOC ## ESPWebDAVCore::begin(FS* fs) ### Description Initializes the WebDAV protocol engine without a dedicated server socket. Used when integrating WebDAV into an existing `ESP8266WebServer` or `WebServer` instance via the hook API. The `ESPWebDAVCore` base class handles all protocol logic; the transport is provided by the hosting web server. ### Method `ESPWebDAVCore::begin(FS* fs)` ### Parameters - **fs** (`FS*`) - A pointer to the mounted filesystem object (e.g., `LittleFS`, `SPIFFS`). ### Usage This method is used when you want to run a standard `ESP8266WebServer` or `WebServer` alongside the WebDAV server on the same port. It initializes the core WebDAV functionality, which is then hooked into the existing web server. ### Request Example ```cpp #include #include #include FS& gfs = LittleFS; ESP8266WebServer server(80); ESPWebDAVCore dav; // Core only — no dedicated WiFiServer void setup() { // ...WiFi setup... LittleFS.begin(); LittleFS.mkdir("/dav"); dav.begin(&gfs); // Initialize core with filesystem only // Hook WebDAV into the web server (see hookWebDAVForWebserver below) server.addHook(hookWebDAVForWebserver("/dav", dav)); server.begin(); } ``` ``` -------------------------------- ### Test WebDAV Root with curl Source: https://context7.com/d-a-v/espwebdav/llms.txt Use curl to send a PROPFIND request to list the root directory of the WebDAV server. This verifies server accessibility and basic WebDAV functionality. ```bash # Test with curl (WebDAV PROPFIND to list root) curl -X PROPFIND http://ESPWebDAV.local/ \ -H "Depth: 1" \ -H "Content-Type: application/xml" \ --data '' ``` -------------------------------- ### setDAVRoot and setFsRoot Source: https://context7.com/d-a-v/espwebdav/llms.txt Configures the WebDAV URL root and the corresponding filesystem root independently, allowing the WebDAV namespace to be decoupled from the filesystem layout. These are typically set automatically by `hookWebDAVForWebserver`. ```APIDOC ## ESPWebDAVCore::setDAVRoot(path) / ESPWebDAVCore::setFsRoot(path) ### Description Configures the DAV URL root (`_davRoot`) and the corresponding filesystem root (`_fsRoot`) independently, enabling the WebDAV namespace to be decoupled from the filesystem layout. `setDAVRoot` sets the URL prefix that the server responds to; `setFsRoot` sets the filesystem directory where files are actually stored. Both are set automatically by `hookWebDAVForWebserver`. ### Parameters - **path** (string) - The URL path prefix for `setDAVRoot` or the filesystem directory path for `setFsRoot`. ``` -------------------------------- ### hookWebDAVForWebserver Source: https://context7.com/d-a-v/espwebdav/llms.txt Creates a Web Server hook to route requests under a specific directory to the ESPWebDAVCore engine, while other requests are handled by the standard web server. An optional filesystem root mapping is also supported. ```APIDOC ## hookWebDAVForWebserver(davRootDir, dav, fsRootDir) ### Description Returns a `WebServer::HookFunction` that intercepts incoming requests before the standard web server handles them. Any request whose URL falls under `davRootDir` is routed to the `ESPWebDAVCore` engine; all other requests pass through to normal web server handlers. The optional `fsRootDir` parameter allows the DAV URL root to be remapped to a different path on the filesystem. ### Parameters - **davRootDir** (string) - The root URL path for WebDAV requests. - **dav** (ESPWebDAVCore) - An instance of the ESPWebDAVCore engine. - **fsRootDir** (string, optional) - The corresponding root path on the filesystem. If not provided, the DAV URL root is used as the filesystem root. ``` -------------------------------- ### Handle Incoming WebDAV Requests Source: https://context7.com/d-a-v/espwebdav/llms.txt This function must be called repeatedly in the loop to process incoming WebDAV requests. It handles the full transaction and supports HTTP/1.1 keep-alive. Avoid long blocking delays to maintain responsiveness. ```cpp void loop() { MDNS.update(); // keep mDNS alive dav.handleClient(); // handles one full HTTP/WebDAV transaction per call // Safe to do other work between calls, but avoid long blocking delays // to maintain responsive WebDAV performance } ``` -------------------------------- ### Download File via curl Source: https://context7.com/d-a-v/espwebdav/llms.txt Download a file from the ESPWebDAV server to the local machine using curl. This showcases file retrieval functionality. ```bash # Download a file curl -o myfile.txt http://ESPWebDAV.local/myfile.txt ``` -------------------------------- ### Upload File via curl Source: https://context7.com/d-a-v/espwebdav/llms.txt Upload a local file to the ESPWebDAV server using curl's HTTP PUT method. This demonstrates file upload capabilities. ```bash # Upload a file via curl (HTTP PUT) curl -T myfile.txt http://ESPWebDAV.local/myfile.txt ``` -------------------------------- ### List Directory Contents to a Stream Source: https://context7.com/d-a-v/espwebdav/llms.txt Prints a human-readable, recursive listing of a specified directory path to any `Print`-compatible output stream, such as `Serial` or a `StreamString`. This is useful for debugging filesystem state. ```cpp // List the entire filesystem to serial dav.dir("/", &Serial); // Example output: // /photos/ (dir) // /photos/img001.jpg (45312 bytes) // /photos/img002.jpg (51008 bytes) // /config.json (256 bytes) // /readme.md (128 bytes) // Can also target a String stream: #include StreamString buf; dav.dir("/photos", &buf); Serial.println(buf); ``` -------------------------------- ### Hook WebDAV for Shared-Port Operation Source: https://context7.com/d-a-v/espwebdav/llms.txt Intercepts incoming requests to route WebDAV traffic to the ESPWebDAVCore engine for URLs under a specified root directory. Other requests pass through to the standard web server. The optional third argument remaps the DAV URL root to a different filesystem path. ```cpp #include #include #include #include #include #define DAVROOT "/" FS& gfs = LittleFS; ESP8266WebServer server(80); ESPWebDAVCore dav; void setup() { // ...WiFi setup... LittleFS.begin(); dav.begin(&gfs); // URL path "/dav/..." maps to FS path "/" (remapped via optional 3rd arg) // Without 3rd arg: URL "/dav/file.txt" <=> FS "/dav/file.txt" // With 3rd arg: URL "/dav/file.txt" <=> FS "/file.txt" server.addHook(hookWebDAVForWebserver(DAVROOT, dav, "/")); // Regular web server routes still work for non-DAV paths server.on("/status", []() { server.send(200, "text/plain", "OK"); }); server.begin(); } void loop() { server.handleClient(); // WebDAV is dispatched transparently via the hook } ``` -------------------------------- ### dir Source: https://context7.com/d-a-v/espwebdav/llms.txt Lists the contents of a directory recursively to a specified `Print`-compatible output stream, such as `Serial` or a `StreamString`. This is useful for debugging filesystem contents. ```APIDOC ## ESPWebDAVCore::dir(path, out) ### Description Prints a human-readable directory listing of `path` (recursively) to any `Print`-compatible output stream such as `Serial`. Useful for debugging filesystem state directly from the serial monitor during development. ### Parameters - **path** (string) - The directory path to list. - **out** (Print*) - A pointer to a `Print`-compatible object (e.g., `Serial`, `StreamString`) where the listing will be written. ``` -------------------------------- ### setIgnored Source: https://context7.com/d-a-v/espwebdav/llms.txt Registers a predicate function to exclude specific URI paths from WebDAV handling. Ignored paths will fall through to the standard web server handler, allowing them to be served by `ESP8266WebServer`. ```APIDOC ## ESPWebDAVCore::setIgnored(fn) ### Description Registers a predicate function that marks specific URI paths as ignored by WebDAV. Ignored paths receive a `CLIENT_REQUEST_CAN_CONTINUE` response from the hook, falling through to the standard web server handler. This allows specific files (e.g., `index.html`, API endpoints) to be served by `ESP8266WebServer` even when WebDAV is mounted at the root (`/`). ### Parameters - **fn** (function) - A predicate function that takes a `String` URI as input and returns `true` if the path should be ignored by WebDAV, `false` otherwise. ``` -------------------------------- ### Exclude Paths from WebDAV Handling Source: https://context7.com/d-a-v/espwebdav/llms.txt Registers a predicate function to ignore specific URI paths for WebDAV handling, allowing them to be served by the standard web server. This is useful for serving files like index.html or API endpoints when WebDAV is mounted at the root. ```cpp // Serve index.html and API calls via the regular web server; // everything else is accessible through WebDAV dav.setIgnored([](const String& uri) { return uri == F("/index.html") || uri == F("/api/status") || uri.startsWith(F("/api/")); }); // Register the corresponding web server handlers server.on(F("/index.html"), []() { server.send_P(200, PSTR("text/html"), PSTR("

Hello from ESP

")); }); server.on(F("/api/status"), []() { server.send(200, "application/json", "{\"heap\":" + String(ESP.getFreeHeap()) + "}"); }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.