{"id":13514307,"url":"https://github.com/perry-mitchell/webdav-client","last_synced_at":"2025-05-14T04:07:30.374Z","repository":{"id":11704102,"uuid":"70310578","full_name":"perry-mitchell/webdav-client","owner":"perry-mitchell","description":"WebDAV client written in Typescript for NodeJS and the browser","archived":false,"fork":false,"pushed_at":"2025-02-16T10:17:12.000Z","size":4519,"stargazers_count":728,"open_issues_count":22,"forks_count":152,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-05-09T14:06:12.769Z","etag":null,"topics":["browser","dav","davfs","javascript","nodejs","webdav","webdav-client"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/perry-mitchell.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["perry-mitchell"]}},"created_at":"2016-10-08T06:50:46.000Z","updated_at":"2025-05-06T13:01:47.000Z","dependencies_parsed_at":"2023-01-16T19:46:32.451Z","dependency_job_id":"bcae856b-c6c2-47a1-970e-0130bfee55d7","html_url":"https://github.com/perry-mitchell/webdav-client","commit_stats":{"total_commits":825,"total_committers":59,"mean_commits":"13.983050847457626","dds":0.2218181818181818,"last_synced_commit":"03fa32e006c8a278eda88f5e0ea9db54e99ceb1b"},"previous_names":[],"tags_count":100,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/perry-mitchell%2Fwebdav-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/perry-mitchell%2Fwebdav-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/perry-mitchell%2Fwebdav-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/perry-mitchell%2Fwebdav-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/perry-mitchell","download_url":"https://codeload.github.com/perry-mitchell/webdav-client/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253441845,"owners_count":21909196,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["browser","dav","davfs","javascript","nodejs","webdav","webdav-client"],"created_at":"2024-08-01T05:00:52.307Z","updated_at":"2025-05-14T04:07:30.343Z","avatar_url":"https://github.com/perry-mitchell.png","language":"TypeScript","readme":"![WebDAV](https://raw.githubusercontent.com/perry-mitchell/webdav-client/master/webdav.jpg)\n\n\u003e A WebDAV client, written in Typescript, for NodeJS and the browser\n\n![build status](https://github.com/perry-mitchell/webdav-client/actions/workflows/test.yml/badge.svg) [![npm version](https://badge.fury.io/js/webdav.svg)](https://www.npmjs.com/package/webdav) [![monthly downloads](https://img.shields.io/npm/dm/webdav.svg)](https://www.npmjs.com/package/webdav) [![total downloads](https://img.shields.io/npm/dt/webdav.svg?label=total%20downloads)](https://www.npmjs.com/package/webdav) ![Dependents (via libraries.io)](https://img.shields.io/librariesio/dependents/npm/webdav)\n\n## About\n\nWebDAV is a well-known, stable and highly flexible protocol for interacting with remote filesystems via an API. Being that it is so widespread, many file hosting services such as **Nextcloud**/**ownCloud**, **Box** and **Yandex** use it as a fallback to their primary interfaces.\n\nThis library provides a **WebDAV client** interface that makes interacting with WebDAV enabled services easy. The API returns promises and resolve with the results. It parses and prepares directory-contents requests for easy consumption, as well as providing methods for fetching things like file stats and quotas.\n\nThis library's motivation is **not** to follow an RFC or to strictly adhere to standard WebDAV interfaces, but to provide an easy-to-consume client API for working with most WebDAV services from Node or the browser.\n\n### Supported Versions / Environments\n\nVersion 5 is under active development. Version 4 is in support mode, and will receive security and stability related bugfixes. Earlier versions are deprecated and will not receive updates.\n\n**Note:** Version 4 support will be dropped January 2025. Migrate to v5 as soon as possible.\n\nVersion 5 upgrades the library to use ESM (ECMAScript Modules), and so your environment must fit one of the following formats to be able to use this library:\n\n * NodeJS project with `\"type\": \"module\"` in `package.json` (ESM mode)\n * Web project bundled with a tool like Webpack that can handle ESM\n * React-native projects (via direct import or using automatic react-native entry)\n\nIf you're not ready to upgrade, you may consider using version 4 of this library.\n\n#### Requests\n\nThis library uses [`@buttercup/fetch`](https://github.com/buttercup/fetch) to make requests in a cross-platform manner. It uses the browser's native `fetch` if present, or a polyfill if not. In Node and other environments it uses [`node-fetch`](https://github.com/node-fetch/node-fetch).\n\nVersions before v5 used Axios for requests.\n\n#### Node support\n\nSupport table:\n\n| Library Major Version | Node JS Range     |\n|-----------------------|-------------------|\n| v5                    | 14+               |\n| v4                    | 10-18             |\n| v3                    | 10-16             |\n| v2                    | 6-14              |\n| v1                    | 4-12              |\n\n#### Browser support\n\nBrowser environments are supported from version 3 onwards of this library.\n\nAs mentioned above, v5 introduced ESM and this may require additional configuration when bundling for the browser.\n\n_Although you may choose to transpile this library's default entry point (NodeJS) yourself, it is not advised - use the dedicated web version instead._\n\nIn version 4 you had to use a different entry-point for the web version, and while this is still possible to use in version 5, you no longer need to:\n\n```typescript\nimport { createClient } from \"webdav/web\";\n\n// or\n\nimport { createClient } from \"webdav\";\n\n// both work fine in supported bundlers\n```\n\nVersions 3/4 supported a UMD-style module in the browser, but this is no longer supported in version 5. Version 5 provides only an ESM-enabled bundle that can be imported into other ESM-supporting projects.\n\n**NB:** Streams are not available within the browser, so `createReadStream` and `createWriteStream` are just stubbed. Calling them will throw an exception.\n\n#### React-Native support\n\nReact-Native is better supported as of version `5.6.0`, using a specific build for the platform. The import should be automatic, but can be forced by importing from `/react-native` directly:\n\n```typescript\nimport { createClient } from \"webdav/react-native\";\n```\n\n**NB:** Note that for some reason, the Metro build system doesn't properly resolve using these entries, and you may need to customise your babel config for React Native to correctly import this library:\n\n```javascript\nmodule.exports = {\n    presets: [\"module:metro-react-native-babel-preset\"],\n    plugins: [\n        [\n            \"module-resolver\",\n            {\n                alias: {\n                    // Point the webdav client entry to the react native build:\n                    webdav: \"webdav/dist/react-native\"\n                },\n                extensions: [\".tsx\", \".ts\", \".js\", \".jsx\", \".json\"]\n            }\n        ]\n    ]\n};\n```\n\nWhen using this override, you can simply import from `webdav`.\n\n### Types\n\nTypescript types are exported with this library for the Node build. All of the types can also be directly imported from the module:\n\n```typescript\nimport { AuthType, createClient } from \"webdav\";\n\nconst client = createClient(\"https://some-server.org\", {\n    authType: AuthType.Digest,\n    username: \"user\",\n    password: \"pass\"\n});\n```\n\n## Installation\n\nSimple install as a dependency using npm:\n\n```\nnpm install webdav --save\n```\n\n## Usage\n\nUsage entails creating a client adapter instance by calling the factory function `createClient`:\n\n```typescript\nconst { createClient } = require(\"webdav\");\n\nconst client = createClient(\n    \"https://webdav.example.com/marie123\",\n    {\n        username: \"marie\",\n        password: \"myS3curePa$$w0rd\"\n    }\n);\n\n// Get directory contents\nconst directoryItems = await client.getDirectoryContents(\"/\");\n// Outputs a structure like:\n// [{\n//     filename: \"/my-file.txt\",\n//     basename: \"my-file.txt\",\n//     lastmod: \"Mon, 10 Oct 2018 23:24:11 GMT\",\n//     size: 371,\n//     type: \"file\"\n// }]\n```\n\n### Authentication \u0026 Connection\n\nThe WebDAV client automatically detects which authentication to use, between `AuthType.None` and `AuthType.Password`, if no `authType` configuration parameter is provided. For `AuthType.Token` or `AuthType.Digest`, you must specify it explicitly.\n\nSetting the `authType` will automatically manage the `Authorization` header when connecting.\n\nYou can set the `authType` to `AuthType.Auto` if you're unsure whether the remote server requires **digest** or **password** based authentication.\n\n#### Basic/no authentication\n\nYou can use the client without authentication if the server doesn't require it - simply avoid passing any values to `username`, `password` in the config.\n\nTo use basic authentication, simply pass a `username` and `password` in the config.\n\nThis library also allows for overriding the built in HTTP and HTTPS agents by setting the properties `httpAgent` \u0026 `httpsAgent` accordingly. These should be instances of node's [http.Agent](https://nodejs.org/api/http.html#http_class_http_agent) and [https.Agent](https://nodejs.org/api/https.html#https_class_https_agent) respectively.\n\n#### OAuth tokens\n\nTo use a token to authenticate, pass the token data to the `token` field and specify the `authType`:\n\n```typescript\ncreateClient(\n    \"https://address.com\",\n    {\n        authType: AuthType.Token,\n        token: {\n            access_token: \"2YotnFZFEjr1zCsicMWpAA\",\n            token_type: \"example\",\n            expires_in: 3600,\n            refresh_token: \"tGzv3JOkF0XG5Qx2TlKWIA\",\n            example_parameter: \"example_value\"\n        }\n    }\n);\n```\n\nYou can also provide the HA1 ([see here for details](https://en.wikipedia.org/wiki/Digest_access_authentication#Overview)) yourself. This enables you to generate the HA1 at the time the user is logged in and persist it, so you do not have persist the password itself.\n\n```typescript\ncreateClient(\"https://address.com\", {\n    authType: AuthType.Digest,\n    username: \"someUser\",\n    password: \"\",\n    ha1: \"your previously generated ha1 here\"\n});\n```\n\n#### Digest authentication\n\nIf a server requires digest-based authentication, you can enable this functionality by the `authType` configuration parameter, as well as providing a `username` and `password`:\n\n```typescript\ncreateClient(\n    \"https://address.com\",\n    {\n        authType: AuthType.Digest,\n        username: \"someUser\",\n        password: \"myS3curePa$$w0rd\"\n    }\n);\n```\n\n### Client configuration\n\nThe `createClient` method takes a WebDAV service URL, and a configuration options parameter.\n\nThe available configuration options are as follows:\n\n| Option        | Default       | Description                                       |\n|---------------|---------------|---------------------------------------------------|\n| `authType`    | `null`        | The authentication type to use. If not provided, defaults to trying to detect based upon whether `username` and `password` were provided. |\n| `attributeNamePrefix` | `@`   | Prefix used to identify attributes on the property object |\n| `contactHref` | _[This URL](https://github.com/perry-mitchell/webdav-client/blob/master/LOCK_CONTACT.md)_ | Contact URL used for LOCKs. |\n| `headers`     | `{}`          | Additional headers provided to all requests. Headers provided here are overridden by method-specific headers, including `Authorization`. |\n| `httpAgent`   | _None_        | HTTP agent instance. Available only in Node. See [http.Agent](https://nodejs.org/api/http.html#http_class_http_agent). |\n| `httpsAgent`  | _None_        | HTTPS agent instance. Available only in Node. See [https.Agent](https://nodejs.org/api/https.html#https_class_https_agent). |\n| `password`    | _None_        | Password for authentication.                      |\n| `token`       | _None_        | Token object for authentication.                  |\n| `username`    | _None_        | Username for authentication.                      |\n| `withCredentials` | _None_    | Credentials inclusion setting for the request,    |\n\n### Client methods\n\nThe `WebDAVClient` interface type contains all the methods and signatures for the WebDAV client instance.\n\n#### copyFile\n\nCopy a file from one location to another.\n\n```typescript\nawait client.copyFile(\n    \"/images/test.jpg\",\n    \"/public/img/test.jpg\"\n);\n```\n\n```typescript\n(filename: string, destination: string, options?: WebDAVMethodOptions) =\u003e Promise\u003cvoid\u003e\n```\n\n| Argument          | Required  | Description                                   |\n|-------------------|-----------|-----------------------------------------------|\n| `filename`        | Yes       | The source filename.                          |\n| `destination`     | Yes       | The destination filename.                     |\n| `options`         | No        | [Method options](#method-options).            |\n\n#### createDirectory\n\nCreate a new directory.\n\n```typescript\nawait client.createDirectory(\"/data/system/storage\");\n```\n\n```typescript\n(path: string, options?: CreateDirectoryOptions) =\u003e Promise\u003cvoid\u003e\n```\n\n| Argument              | Required  | Description                                   |\n|-----------------------|-----------|-----------------------------------------------|\n| `path`                | Yes       | The path to create.                           |\n| `options`             | No        | Create directory options.                     |\n| `options.recursive`   | No        | Recursively create directories if they do not exist. |\n\n_`options` extends [method options](#method-options)._\n\n##### Recursive creation\n\nRecursive directory creation is expensive request-wise. Multiple `stat` requests are made (totalling the depth of the path that exists, +1) to detect what parts of the path already exist, until finding a segment that doesn't exist - where it then only requests the _creation_ method.\n\nFor example, a recursive call to create a path `/a/b/c/d/e`, where `/a/b` already exists, will result in **3** `stat` requests (for `/a`, `/a/b` and `/a/b/c`) and **3** `createDirectory` requests (for `/a/b/c`, `/a/b/c/d` and `/a/b/c/d/e`).\n\n#### createReadStream\n\nSynchronously create a readable stream for a remote file.\n\n_Note that although a stream is returned instantly, the connection and fetching of the file is still performed asynchronously in the background. There will be some delay before the stream begins receiving data._\n\n```typescript\nclient\n    .createReadStream(\"/video.mp4\")\n    .pipe(fs.createWriteStream(\"~/video.mp4\"));\n```\n\nIf you want to stream only part of the file, you can specify the `range` in the options argument:\n\n```typescript\nclient\n    .createReadStream(\n        \"/video.mp4\", \n        { range: { start: 0, end: 1024 } }\n    ).pipe(fs.createWriteStream(\"~/video.mp4\"));\n```\n\n```typescript\n(filename: string, options?: CreateReadStreamOptions) =\u003e Stream.Readable\n```\n\n| Argument          | Required  | Description                                   |\n|-------------------|-----------|-----------------------------------------------|\n| `callback`        | No        | Callback to fire with the response of the request. |\n| `filename`        | Yes       | The remote file to stream.                    |\n| `options`         | No        | Read stream options.                          |\n| `options.range`   | No        | Stream range configuration.                   |\n| `options.range.start` | Yes   | Byte-position for the start of the stream.    |\n| `options.range.end` | No      | Byte-position for the end of the stream.      |\n\n_`options` extends [method options](#method-options)._\n\n#### createWriteStream\n\nCreate a write stream targeted at a remote file.\n\n_Note that although a stream is returned instantly, the connection and writing to the remote file is still performed asynchronously in the background. There will be some delay before the stream begins piping data._\n\n```typescript\nfs\n    .createReadStream(\"~/Music/song.mp3\")\n    .pipe(client.createWriteStream(\"/music/song.mp3\"));\n```\n\n```typescript\n(filename: string, options?: CreateWriteStreamOptions, callback?: CreateWriteStreamCallback) =\u003e Stream.Writable\n```\n\n| Argument          | Required  | Description                                   |\n|-------------------|-----------|-----------------------------------------------|\n| `filename`        | Yes       | The remote file to stream.                    |\n| `options`         | No        | Write stream options.                         |\n| `options.overwrite` | No      | Whether or not to overwrite the remote file if it already exists. Defaults to `true`. |\n| `callback`        | No        | Callback to fire once the connection has been made and streaming has started. Callback is called with the response of the request. |\n\n_`options` extends [method options](#method-options)._\n\n#### customRequest\n\nCustom requests can be made to the attached host by calling `customRequest`. Custom requests provide the boilerplate authentication and other request options used internally within the client.\n\n```typescript\nconst resp: Response = await this.client.customRequest(\"/alrighty.jpg\", {\n    method: \"PROPFIND\",\n    headers: {\n        Accept: \"text/plain\",\n        Depth: \"0\"\n    }\n});\nconst result: DAVResult = await parseXML(await resp.text());\nconst stat: FileStat = parseStat(result, \"/alrighty.jpg\", false);\n```\n\n```typescript\n(path: string, requestOptions: RequestOptionsCustom) =\u003e Promise\u003cResponse\u003e\n```\n\n| Argument          | Required  | Description                                   |\n|-------------------|-----------|-----------------------------------------------|\n| `path`            | Yes       | The path to make a custom request against.    |\n| `requestOptions`  | Yes       | Request options - required parameters such as `url`, `method` etc. - Refer to the `RequestOptionsCustom` type definition. |\n\n_The request options parameter **does not** extend [method options](#method-options) as things like `headers` can already be specified._\n\n#### deleteFile\n\nDelete a remote file.\n\n```typescript\nawait client.deleteFile(\"/tmp.dat\");\n```\n\n```typescript\n(filename: string, options?: WebDAVMethodOptions) =\u003e Promise\u003cvoid\u003e\n```\n\n| Argument          | Required  | Description                                   |\n|-------------------|-----------|-----------------------------------------------|\n| `filename`        | Yes       | The file to delete.                           |\n| `options`         | No        | [Method options](#method-options).            |\n\n#### exists\n\nCheck if a file or directory exists.\n\n```typescript\nif (await client.exists(\"/some/path\") === false) {\n    await client.createDirectory(\"/some/path\");\n}\n```\n\n```typescript\n(path: string, options?: WebDAVMethodOptions) =\u003e Promise\u003cboolean\u003e\n```\n\n| Argument          | Required  | Description                                   |\n|-------------------|-----------|-----------------------------------------------|\n| `path`            | Yes       | The remote path to check.                     |\n| `options`         | No        | [Method options](#method-options).            |\n\n#### getDirectoryContents\n\nGet the contents of a remote directory. Returns an array of [item stats](#item-stats).\n\n```typescript\n// Get current directory contents:\nconst contents = await client.getDirectoryContents(\"/\");\n// Get all contents:\nconst contents = await client.getDirectoryContents(\"/\", { deep: true });\n```\n\nFiles can be globbed using the `glob` option (processed using [`minimatch`](https://github.com/isaacs/minimatch)). When using a glob pattern it is recommended to fetch `deep` contents:\n\n```typescript\nconst images = await client.getDirectoryContents(\"/\", { deep: true, glob: \"/**/*.{png,jpg,gif}\" });\n```\n\n```typescript\n(path: string, options?: GetDirectoryContentsOptions) =\u003e Promise\u003cArray\u003cFileStat\u003e | ResponseDataDetailed\u003cArray\u003cFileStat\u003e\u003e\u003e\n```\n\n| Argument          | Required  | Description                                   |\n|-------------------|-----------|-----------------------------------------------|\n| `path`            | Yes       | The path to fetch the contents of.            |\n| `options`         | No        | Configuration options.                        |\n| `options.deep`    | No        | Fetch deep results (recursive). Defaults to `false`. |\n| `options.details` | No        | Fetch detailed results (item stats, headers). Defaults to `false`. |\n| `options.glob`    | No        | Glob string for matching filenames. Not set by default. |\n\n_`options` extends [method options](#method-options)._\n\n#### getFileContents\n\nFetch the contents of a remote file. Binary contents are returned by default (`Buffer`):\n\n```typescript\nconst buff: Buffer = await client.getFileContents(\"/package.zip\");\n```\n\n_It is recommended to use streams if the files being transferred are large._\n\nText files can also be fetched:\n\n```typescript\nconst str: string = await client.getFileContents(\"/config.json\", { format: \"text\" });\n```\n\n```typescript\n(filename: string, options?: GetFileContentsOptions) =\u003e Promise\u003cBufferLike | string | ResponseDataDetailed\u003cBufferLike | string\u003e\u003e\n```\n\n| Argument          | Required  | Description                                   |\n|-------------------|-----------|-----------------------------------------------|\n| `filename`        | Yes       | The file to fetch the contents of.            |\n| `options`         | No        | Configuration options.                        |\n| `options.details` | No        | Fetch detailed results (additional headers). Defaults to `false`. |\n| `options.format`  | No        | Whether to fetch binary (\"binary\") data or textual (\"text\"). Defaults to \"binary\". |\n\n_`options` extends [method options](#method-options)._\n\n#### getFileDownloadLink\n\nGenerate a public link where a file can be downloaded. This method is synchronous. **Exposes authentication details in the URL**.\n\n_Not all servers may support this feature. Only Basic authentication and unauthenticated connections support this method._\n\n```typescript\nconst downloadLink: string = client.getFileDownloadLink(\"/image.png\");\n```\n\n```typescript\n(filename: string) =\u003e string\n```\n\n| Argument          | Required  | Description                                   |\n|-------------------|-----------|-----------------------------------------------|\n| `filename`        | Yes       | The remote file to generate a download link for. |\n\n#### getFileUploadLink\n\nGenerate a URL for a file upload. This method is synchronous. **Exposes authentication details in the URL**.\n\n```typescript\nconst uploadLink: string = client.getFileUploadLink(\"/image.png\");\n```\n\n```typescript\n(filename: string) =\u003e string\n```\n\n| Argument          | Required  | Description                                   |\n|-------------------|-----------|-----------------------------------------------|\n| `filename`        | Yes       | The remote file to generate an upload link for. |\n\n#### getQuota\n\nGet the quota information for the current account:\n\n```typescript\nconst quota: DiskQuota = await client.getQuota();\n// {\n//     \"used\": 1938743,\n//     \"available\": \"unlimited\"\n// }\n```\n\n```typescript\n(options?: GetQuotaOptions) =\u003e Promise\u003cDiskQuota | null | ResponseDataDetailed\u003cDiskQuota | null\u003e\u003e\n```\n\n| Argument          | Required  | Description                                   |\n|-------------------|-----------|-----------------------------------------------|\n| `options`         | No        | Configuration options.                        |\n| `options.details` | No        | Return detailed results (headers etc.). Defaults to `false`. |\n| `options.path`    | No        | Path used to make the quota request.          |\n\n_`options` extends [method options](#method-options)._\n\n#### lock\n\nLock a remote resource (using a **write** lock).\n\n```typescript\nconst lock = await client.lock(\"/file.doc\");\n\n// Later\nawait client.unlock(\"/file.doc\", lock.token);\n```\n\n```typescript\n(path: string, options?: LockOptions) =\u003e Promise\u003cLockResponse\u003e\n```\n\n| Argument          | Required  | Description                                   |\n|-------------------|-----------|-----------------------------------------------|\n| `path`            | Yes       | The path to lock.                             |\n| `options`         | No        | Configuration options.                        |\n| `options.timeout` | No        | WebDAV lock requested timeout. See the [WebDAV `Timeout` header documentation](https://docs.microsoft.com/en-us/previous-versions/office/developer/exchange-server-2003/aa143141(v=exchg.65)). |\n| `options.refreshToken` | No   | Previous valid lock token that should be refreshed. |\n\n_`options` extends [method options](#method-options)._\n\n#### moveFile\n\nMove a file to another location.\n\n```typescript\nawait client.moveFile(\"/file1.png\", \"/file2.png\");\n```\n\n```typescript\n(filename: string, destinationFilename: string, options?: WebDAVMethodOptions) =\u003e Promise\u003cvoid\u003e\n```\n\n| Argument          | Required  | Description                                   |\n|-------------------|-----------|-----------------------------------------------|\n| `filename`        | Yes       | File to move.                                 |\n| `destinationFilename` | Yes   | Destination filename.                         |\n| `options`         | No        | [Method options](#method-options).            |\n\n#### putFileContents\n\nWrite data to a remote file. Returns `false` when file was not written (eg. `{ overwrite: false }` and file exists), and `true` otherwise.\n\n```typescript\n// Write a buffer:\nawait client.putFileContents(\"/my/file.jpg\", imageBuffer, { overwrite: false });\n// Write a text file:\nawait client.putFileContents(\"/my/file.txt\", str);\n```\n\n```typescript\n(filename: string, data: string | BufferLike | Stream.Readable, options?: PutFileContentsOptions) =\u003e Promise\u003cboolean\u003e\n```\n\n| Argument          | Required  | Description                                   |\n|-------------------|-----------|-----------------------------------------------|\n| `filename`        | Yes       | File to write to.                             |\n| `data`            | Yes       | The data to write. Can be a string, buffer or a readable stream. |\n| `options`         | No        | Configuration options.                        |\n| `options.contentLength` | No  | Data content length override. Either a boolean (`true` (**default**) = calculate, `false` = don't set) or a number indicating the exact byte length of the file. |\n| `options.overwrite` | No      | Whether or not to override the remote file if it exists. Defaults to `true`. |\n\n_`options` extends [method options](#method-options)._\n\n#### partialUpdateFileContents\n\nUpdate a remote file with a partial update. This method is useful for updating a file without having to download and re-upload the entire file.\n\n**_Note that this method is not standardised and may not be supported by all servers._** To use this feature, one of the following must be met:\n * WebDav is served by Apache with the [mod_dav](https://httpd.apache.org/docs/2.4/mod/mod_dav.html) module\n * The server supports Sabredav PartialUpdate Extension (https://sabre.io/dav/http-patch/)\n\n```typescript\n(filePath: string, start: number, end: number, data: string | BufferLike | Stream.Readable, options?: WebDAVMethodOptions)=\u003e Promise\u003cvoid\u003e\n```\n\n| Argument          | Required  | Description                                   |\n|-------------------|-----------|-----------------------------------------------|\n| `filePath`        | Yes       | File to update.                               |\n| `start`           | Yes       | Start byte position. (inclusive)              |\n| `end`             | Yes       | End byte position.   (inclusive)              |\n| `data`            | Yes       | The data to write. Can be a string, buffer or a readable stream. |\n| `options`         | No        | Configuration options.                        |\n\n#### search\n\nPerform a WebDAV search as per [rfc5323](https://www.ietf.org/rfc/rfc5323.html).\n\n```typescript\nconst searchRequest = `\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\u003cd:searchrequest xmlns:d=\"DAV:\" xmlns:f=\"http://example.com/foo\"\u003e\n    \u003cf:natural-language-query\u003e\n    Find files changed last week\n    \u003c/f:natural-language-query\u003e\n\u003c/d:searchrequest\u003e\n`\nconst result: SearchResult = await client.search(\"/some-collection\", { data: searchRequest });\n```\n\n```typescript\n(path: string, options?: SearchOptions) =\u003e Promise\u003cSearchResult | ResponseDataDetailed\u003cSearchResult\u003e\u003e\n```\n\n| Argument          | Required  | Description                                   |\n|-------------------|-----------|-----------------------------------------------|\n| `path`            | Yes       | Remote path to which executes the search.     |\n| `options`         | No        | Configuration options.                        |\n| `options.details` | No        | Return detailed results (headers etc.). Defaults to `false`. |\n\n_`options` extends [method options](#method-options)._\n\n#### stat\n\nGet a file or directory stat object. Returns an [item stat](#item-stats).\n\n```typescript\nconst stat: FileStat = await client.stat(\"/some/file.tar.gz\");\n```\n\n```typescript\n(path: string, options?: StatOptions) =\u003e Promise\u003cFileStat | ResponseDataDetailed\u003cFileStat\u003e\u003e\n```\n\n| Argument          | Required  | Description                                   |\n|-------------------|-----------|-----------------------------------------------|\n| `path`            | Yes       | Remote path to stat.                          |\n| `options`         | No        | Configuration options.                        |\n| `options.details` | No        | Return detailed results (headers etc.). Defaults to `false`. |\n\n_`options` extends [method options](#method-options)._\n\n#### unlock\n\nUnlock a locked resource using a token.\n\n```typescript\nawait client.unlock(\"/file.doc\", lock.token);\n```\n\n```typescript\n(path: string, token:string, options?: WebDAVMethodOptions) =\u003e Promise\u003cvoid\u003e\n```\n\n| Argument          | Required  | Description                                   |\n|-------------------|-----------|-----------------------------------------------|\n| `path`            | Yes       | Remote path to unlock.                        |\n| `token`           | Yes       | Token string from a previous lock request.    |\n| `options`         | No        | Configuration options.                        |\n\n_`options` extends [method options](#method-options)._\n\n#### registerAttributeParser\n\nRegister a new attribute parser on the client\n\n```typescript\n// Parses all `disabled` attributes to boolean, e.g. `\u003cprop disabled=\"true\"\u003e`\nfunction booleanAttributeParser(jPath: string, value: string) {\n    if (jPath.endsWith(\".disabled\")) {\n        return value === \"true\";\n    }\n    // Apply default parsing otherwise\n    return value;\n}\nawait client.registerAttributeParser(booleanAttributeParser);\n```\n\n```typescript\n(parser: WebDAVAttributeParser) =\u003e void\n```\n\nThe `WebDAVAttributeParser` is a function that receives the jPath and the attribute value and either returns:\n- `undefined` to use the value as it is and skip any further parsing\n- the unchanged value to apply default parsing\n- Any other parsed value to use\n\n```typescript\n(jPath: string, value: string) =\u003e undefined|string|unknown\n```\n\n#### registerTagParser\n\nRegister a new tag parser on the client, this is used to parse the value of props when doing stat requests.\n\n```typescript\n// Parses only \u003cprop\u003e\u003cjson-prop\u003eJSONVALUE\u003c/json-prop\u003e\u003c/prop\u003e\nfunction jsonPropParser(jPath: string, value: string) {\n    if (jPath.endsWith(\"prop.json-prop\")) {\n        return JSON.parse(value);\n    }\n    // Apply default parsing otherwise\n    return value;\n}\nawait client.registerTagParser(jsonPropParser);\n```\n\n```typescript\n(parser: WebDAVTagParser) =\u003e void\n```\n\nThe `WebDAVTagParser` is a function that receives the jPath and the attribute value and either returns:\n- `undefined` to use the value as it is and skip any further parsing\n- the unchanged value to apply default parsing\n- Any other parsed value to use\n\n```typescript\n(jPath: string, value: string) =\u003e undefined|string|unknown\n```\n\n##### Custom properties\n\nFor requests like `stat`, which use the `PROPFIND` method under the hood, it is possible to provide a custom request body to the method so that the server may respond with additional/different data. Overriding of the body can be performed by setting the `data` property in the [method options](#method-options).\n\n### Method options\n\nMost WebDAV methods extend `WebDAVMethodOptions`, which allow setting things like custom headers.\n\n| Option            | Required  | Description                                   |\n|-------------------|-----------|-----------------------------------------------|\n| `data`            | No        | Optional body/data value to send in the request. This overrides the original body of the request, if applicable. |\n| `headers`         | No        | Optional headers object to apply to the request. These headers override all others, so be careful. |\n| `signal`          | No        | Instance of [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal), for aborting requests. |\n\n### Common data structures\n\n#### Item stats\n\nItem stats are objects with properties that describe a file or directory. They resemble the following:\n\n```json\n{\n    \"filename\": \"/test\",\n    \"basename\": \"test\",\n    \"lastmod\": \"Tue, 05 Apr 2016 14:39:18 GMT\",\n    \"size\": 0,\n    \"type\": \"directory\",\n    \"etag\": null\n}\n```\n\nor:\n\n```json\n{\n    \"filename\": \"/image.jpg\",\n    \"basename\": \"image.jpg\",\n    \"lastmod\": \"Sun, 13 Mar 2016 04:23:32 GMT\",\n    \"size\": 42497,\n    \"type\": \"file\",\n    \"mime\": \"image/jpeg\",\n    \"etag\": \"33a728c7f288ede1fecc90ac6a10e062\"\n}\n```\n\nProperties:\n\n| Property name | Type    | Present      | Description                                 |\n|---------------|---------|--------------|---------------------------------------------|\n| filename      | String  | Always       | File path of the remote item                |\n| basename      | String  | Always       | Base filename of the remote item, no path   |\n| lastmod       | String  | Always       | Last modification date of the item          |\n| size          | Number  | Always       | File size - 0 for directories               |\n| type          | String  | Always       | Item type - \"file\" or \"directory\"           |\n| mime          | String  | Files only   | Mime type - for file items only             |\n| etag          | String / null | When supported | [ETag](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ETag) of the file |\n| props         | Object  | `details: true` | Props object containing all item properties returned by the server |\n\n\n#### Detailed responses\n\nRequests that return results, such as `getDirectoryContents`, `getFileContents`, `getQuota`, `search` and `stat`, can be configured to return more detailed information, such as response headers. Pass `{ details: true }` to their options argument to receive an object like the following:\n\n| Property     | Type            | Description                            |\n|--------------|-----------------|----------------------------------------|\n| data         | *               | The data returned by the procedure. Will be whatever type is returned by calling without `{ details: true }` |\n| headers      | Object          | The response headers.                  |\n| status       | Number          | The numeric status code.               |\n| statusText   | String          | The status text.                       |\n\nIn the following example the `system-tag` prop contained attributes which you can identify by providing the `attributeNamePrefix` (by default `@`), with the value is then contained in the `text` attribute:\n\n```json\n{\n    \"headers\": {},\n    \"status\": 200,\n    \"statusText\": \"Ok\",\n    \"data\": {\n        \"filename\": \"/1\",\n        \"basename\": \"1\",\n        \"lastmod\": \"Wed, 24 Jul 2024 19:46:09 GMT\",\n        \"size\": 0,\n        \"type\": \"file\",\n        \"etag\": \"66a15a0171527\",\n        \"mime\": \"\",\n        \"props\": {\n            \"getetag\": \"\\\"66a15a0171527\\\"\",\n            \"getlastmodified\": \"Wed, 24 Jul 2024 19:46:09 GMT\",\n            \"creationdate\": \"1970-01-01T00:00:00+00:00\",\n            \"system-tags\": {\n                \"system-tag\": [\n                    {\n                        \"text\": \"Tag1\",\n                        \"@can-assign\": \"true\",\n                        \"@id\": \"321\",\n                        \"@checked\": true\n                    },\n                    {\n                        \"text\": \"Tag2\",\n                        \"@can-assign\": \"false\",\n                        \"@id\": \"654\",\n                        \"@prop\": \"\"\n                    }\n                ]\n            }\n        }\n    },\n}\n```\n\n### CORS\nCORS is a security enforcement technique employed by browsers to ensure requests are executed to and from expected contexts. It can conflict with this library if the target server doesn't return CORS headers when making requests from a browser. It is your responsibility to handle this.\n\nIt is a known issue that Nextcloud servers by default don't return friendly CORS headers, making working with this library within a browser context impossible. You can of course force the addition of CORS headers (Apache or Nginx configs) yourself, but do this at your own risk.\n\n## Projects using this WebDAV client\n\n * [Buttercup Password Manager](https://github.com/buttercup)\n * [Nextcloud Server](https://github.com/nextcloud/server)\n * [Nextcloud Photos](https://github.com/nextcloud/photos)\n * [ownCloud SDK](https://github.com/owncloud/owncloud-sdk)\n * [React OxIDE](https://github.com/bootrino/reactoxide)\n * [BackItUp](https://github.com/simatec/ioBroker.backitup)\n","funding_links":["https://github.com/sponsors/perry-mitchell"],"categories":["Libraries"],"sub_categories":["JavaScript"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fperry-mitchell%2Fwebdav-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fperry-mitchell%2Fwebdav-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fperry-mitchell%2Fwebdav-client/lists"}