webdav_list_files: List files from a specific folder on WebDAV server

View source: R/webdav.R

webdav_list_filesR Documentation

List files from a specific folder on WebDAV server

Description

This function lists the files in a specific folder on the WebDAV server. If no folder path is provided, it lists files from the root directory. The function validates the provided parameters and handles errors during the process.

Usage

webdav_list_files(
  base_url,
  folder_path = NULL,
  username = Sys.getenv("WEBDAV_USERNAME"),
  password = Sys.getenv("WEBDAV_PASSWORD"),
  depth = 1,
  verbose = FALSE
)

Arguments

base_url

The base URL of the WebDAV server.

folder_path

The path inside WebDAV where the files are located. If not provided or empty, the root folder will be listed.

username

The username for WebDAV authentication. Defaults to the "WEBDAV_USERNAME" environment variable.

password

The password for WebDAV authentication. Defaults to the "WEBDAV_PASSWORD" environment variable.

depth

The depth of the PROPFIND request (default is 1).

verbose

Logical value indicating whether to print detailed debug messages. When TRUE, the function outputs additional information about its progress and actions.

Value

A tibble containing:

file_name

The name of the file.

relative_path

The path of the file relative to the specified folder.

lastmodified

The date and time when the file was last modified.

content_length

The size of the file in bytes.

Returns 'NULL' if an error occurs during the execution of the function.

Examples

# Example usage with a public WebDAV server.
# Visit test_server$url link to view the results of the operation.
library(magrittr)
library(httr2)
test_server <- "https://www.webdavserver.com/" %>%
  request() %>%
  req_retry(max_tries = 1, max_seconds = 2, backoff =  ~ 1) %>%
  req_perform() %>%
  try(silent = TRUE)

# List files in a directory
if (class(test_server) != "try-error")
  webdav_list_files(base_url = test_server$url, folder_path = "Sales/", verbose = TRUE)


webdav documentation built on April 3, 2025, 10:13 p.m.