| Title: | Simple 'WebDAV' Client |
|---|---|
| Description: | A simple 'WebDAV' client that provides functions to fetch and send files or folders to servers using the 'WebDAV' protocol (see 'RFC' 4918 <https://www.rfc-editor.org/rfc/rfc4918>). Only a subset of the protocol is implemented (e.g. file locks are not yet supported). |
| Authors: | Gunther Krauss [aut, cre] |
| Maintainer: | Gunther Krauss <[email protected]> |
| License: | GPL-2 |
| Version: | 0.3.0 |
| Built: | 2026-06-04 07:02:49 UTC |
| Source: | https://github.com/gk-crop/rdav |
Builds the Nextcloud base URL for a nextcloud server from host and user names
ncl_baseurl(hostname, username, path_prefix = "")ncl_baseurl(hostname, username, path_prefix = "")
hostname |
host name |
username |
user name |
path_prefix |
optional path to webdav directory |
base url to use with wd_connect
ncl_baseurl("example.com","johndoe") ncl_baseurl("example.com","johndoe","sub/dir/")ncl_baseurl("example.com","johndoe") ncl_baseurl("example.com","johndoe","sub/dir/")
Extracts the user name from a Nextcloud Base URL
ncl_username_from_url(url)ncl_username_from_url(url)
url |
base or share url |
user name
ncl_username_from_url("https://example.com/remote.php/dav/files/johndoe")ncl_username_from_url("https://example.com/remote.php/dav/files/johndoe")
Search for users one could share data
ocs_find_users(req, search, lookup = FALSE, as_df = TRUE)ocs_find_users(req, search, lookup = FALSE, as_df = TRUE)
req |
WebDAV request as returned by |
search |
search string (e.g. user name, e-mail, group name) |
lookup |
if TRUE (and supported) search on Nextcloud lookup server |
as_df |
if TRUE (default) a data.frame is returned, else a list of IDs |
data.frame with user informations or named vector of user ids.
## Not run: r <- wd_connect("https://example.com/remote.php/dav/files/johndoe") ocs_find_users(r, "Doe, Jack") ## End(Not run)## Not run: r <- wd_connect("https://example.com/remote.php/dav/files/johndoe") ocs_find_users(r, "Doe, Jack") ## End(Not run)
Notifies the user of a mail share
ocs_send_mail(req, id, password = NULL)ocs_send_mail(req, id, password = NULL)
req |
WebDAV request as returned by |
id |
share id |
password |
password of the share if it is password protected |
invisible TRUE on success or FALSE on failure
## Not run: r <- wd_connect("https://example.com/remote.php/dav/files/johndoe") # add a password to a mail share and notify the user ocs_modify_share(r, 12342, password = "super_secret") ocs_send_mail(r, 12342, password = "super_secret") ## End(Not run)## Not run: r <- wd_connect("https://example.com/remote.php/dav/files/johndoe") # add a password to a mail share and notify the user ocs_modify_share(r, 12342, password = "super_secret") ocs_send_mail(r, 12342, password = "super_secret") ## End(Not run)
Provides functions to interchange files with WebDAV servers
download a file or a directory (recursively) from a WebDAV server
upload a file or a directory (recursively) to a WebDAV server
copy, move, delete files or directories on a WebDAV server
list directories on the WebDAV server
Notice: when uploading or downloading files, they are overwritten without any warnings.
Provides additional functions for Nextcloud servers for managing shares.
Gunther Krauss
Useful links:
## Not run: # establish a connection, you will be asked for a password r <- wd_connect("https://example.com/remote.php/dav/files/user","user") # show files / directoriess in main directory wd_dir(r) # lists 'subdir', returns a dataframe wd_dir(r, "subdir", as_df = TRUE) # create directory 'mydirectory' on the server wd_mkdir(r,"mydirectory") # upload the local file testfile.R to the subdirectory 'mydirectory' wd_upload(r, "testfile.R", "mydirectory/testfile.R") # download content of 'mydirectory' from the server and # store it in 'd:/data/fromserver' on your computer wd_download(r, "mydirectory", "d:/data/fromserver") ## End(Not run)## Not run: # establish a connection, you will be asked for a password r <- wd_connect("https://example.com/remote.php/dav/files/user","user") # show files / directoriess in main directory wd_dir(r) # lists 'subdir', returns a dataframe wd_dir(r, "subdir", as_df = TRUE) # create directory 'mydirectory' on the server wd_mkdir(r,"mydirectory") # upload the local file testfile.R to the subdirectory 'mydirectory' wd_upload(r, "testfile.R", "mydirectory/testfile.R") # download content of 'mydirectory' from the server and # store it in 'd:/data/fromserver' on your computer wd_download(r, "mydirectory", "d:/data/fromserver") ## End(Not run)
Creates and authenticate a request handle to the WebDAV server
wd_connect( url, username = ncl_username_from_url(url), password = NULL, directory = "/" )wd_connect( url, username = ncl_username_from_url(url), password = NULL, directory = "/" )
url |
url of the WebDAV directory |
username |
username - if not given, it will be derived from the url |
password |
password - if not given, you will be asked for it |
directory |
path to use as working directory |
Notice: it's not recommended to write the password as plain text. Either omit the parameter (then you will be asked to enter a password interactively) or use for example the system credential store via keyring package.
a httr2 request to the WebDAV server location
## Not run: # establish a connection, you will be asked for a password r <- wd_connect("https://example.com/remote.php/dav/files/myname","myname") # establish a connection, use keyring package to retrieve the password keyring::key_set("dav", "myname") # call only once r <- wd_connect("https://example.com/remote.php/dav/files/myname", "myname", keyring::key_get("dav", "myname")) ## End(Not run)## Not run: # establish a connection, you will be asked for a password r <- wd_connect("https://example.com/remote.php/dav/files/myname","myname") # establish a connection, use keyring package to retrieve the password keyring::key_set("dav", "myname") # call only once r <- wd_connect("https://example.com/remote.php/dav/files/myname", "myname", keyring::key_get("dav", "myname")) ## End(Not run)
Copies a file or directory on the WebDAV server
wd_copy(req, source, target, overwrite = TRUE)wd_copy(req, source, target, overwrite = TRUE)
req |
request handle obtained from |
source |
path of the source on the server |
target |
path of the target on the server |
overwrite |
overwrites files when TRUE (default) |
TRUE on success, FALSE on failure (invisibly)
## Not run: wd_copy(r, "testfile.R", "testfile_old.R") ## End(Not run)## Not run: wd_copy(r, "testfile.R", "testfile_old.R") ## End(Not run)
Deletes a file or directory (collection) on WebDAV server
wd_delete(req, file)wd_delete(req, file)
req |
request handle obtained from |
file |
path to file or directory to delete on the server |
TRUE on success, FALSE on failure (invisibly)
## Not run: wd_delete(r, "testfile.R") ## End(Not run)## Not run: wd_delete(r, "testfile.R") ## End(Not run)
Lists the content of a WebDAV directory
wd_dir(req, directory = "", full_names = FALSE, as_df = FALSE)wd_dir(req, directory = "", full_names = FALSE, as_df = FALSE)
req |
request handle obtained from |
directory |
directory path |
full_names |
if TRUE, the directory path is prepended to the file names to give a relative file path (relevant only if as_df is FALSE) |
as_df |
if TRUE outputs a data.frame with file information |
a vector of filenames or a dataframe (when as_df is TRUE) with detailed file information (filename, path, isdir, size, lastmodified)
## Not run: # lists names of files and directories in the main directory wd_dir(r) # lists names of files and directories in the subdirectory "mydirectory" wd_dir(r, "mydirectory") # lists names of files and directories with the relative path wd_dir(r, "mydirectory", full_names=TRUE) # returns a data.frame with the columns filename, size and isdir (whether # it's a directory or file wd_dir(r, "mydirectory", as_df=TRUE) ## End(Not run)## Not run: # lists names of files and directories in the main directory wd_dir(r) # lists names of files and directories in the subdirectory "mydirectory" wd_dir(r, "mydirectory") # lists names of files and directories with the relative path wd_dir(r, "mydirectory", full_names=TRUE) # returns a data.frame with the columns filename, size and isdir (whether # it's a directory or file wd_dir(r, "mydirectory", as_df=TRUE) ## End(Not run)
Directories are downloaded recursively.
If the source is a file and the target a directory, then the file is
downloaded to the target directory.
If the target is omitted, then the file or directory name
(basename) will be used.
wd_download(req, source, target = "")wd_download(req, source, target = "")
req |
request handle obtained from |
source |
path to source file or directory on server |
target |
path to local target file or directory, if omitted the file or directory name will be used, if source is a file and target a directory then the file will be put into the target directory |
vector of downloaded files (invisibly)
## Not run: wd_download(r, "weatherfiles", "d:/data/weather") wd_download(r, "test/xyz.txt", "d:/data/abc.txt") ## End(Not run)## Not run: wd_download(r, "weatherfiles", "d:/data/weather") wd_download(r, "test/xyz.txt", "d:/data/abc.txt") ## End(Not run)
Get the current WebDAV working directory
wd_getwd(req)wd_getwd(req)
req |
request handle obtained from |
name of the WebDAV directory
## Not run: wd_getwd(req) ## End(Not run)## Not run: wd_getwd(req) ## End(Not run)
Checks if the resource on WebDAV is a directory
wd_isdir(req, directory, silent = FALSE)wd_isdir(req, directory, silent = FALSE)
req |
request handle obtained from |
directory |
path to directory |
silent |
if FALSE a warning is given if the directory does not exists |
TRUE if it is a directory, FALSE else
## Not run: wd_isdir(r, "testfile.R") # FALSE wd_isdir(r, "mydirectory") # TRUE ## End(Not run)## Not run: wd_isdir(r, "testfile.R") # FALSE wd_isdir(r, "mydirectory") # TRUE ## End(Not run)
When creating a subdirectoy, all parent directories have to exist on the server.
wd_mkdir(req, directory)wd_mkdir(req, directory)
req |
request handle obtained from |
directory |
directory path on server |
TRUE on success, FALSE on failure (invisibly)
## Not run: # creates 'newdir' inside the subdirectory 'existing/directory' wd_mkdir(r, "existing/directory/newdir") ## End(Not run)## Not run: # creates 'newdir' inside the subdirectory 'existing/directory' wd_mkdir(r, "existing/directory/newdir") ## End(Not run)
Moves a file or directory on the server
wd_move(req, source, target, overwrite = TRUE)wd_move(req, source, target, overwrite = TRUE)
req |
request handle obtained from |
source |
path of the source on the server |
target |
path of the target on the server |
overwrite |
overwrites files when TRUE (default) |
TRUE on success, FALSE on failure (invisibly)
## Not run: wd_move(r, "testfile.R", "testfile_old.R") ## End(Not run)## Not run: wd_move(r, "testfile.R", "testfile_old.R") ## End(Not run)
If the directory path starts with a forward slash, then it is set from the WebDAV's root directory. Otherwise it's set in the current directory.
wd_setwd(req, directory)wd_setwd(req, directory)
req |
request handle obtained from |
directory |
WebDAV directory |
If the directory does not exist, then the request is not modified.
Notice: One has to (re)assign the returned request, as it is not modified in place.
modified request
## Not run: req <- wd_setwd(req, "/maindir") req <- wd_setwd(req, "subdir") req <- wd_setwd(req, "/othermain") ## End(Not run)## Not run: req <- wd_setwd(req, "/maindir") req <- wd_setwd(req, "subdir") req <- wd_setwd(req, "/othermain") ## End(Not run)
Directories are uploaded recursively.
If the source is a file and the target a directory, then the file is uploaded
into the directory.
If the target is omitted, then the file or directory name
(basename) will be used.
wd_upload(req, source, target = "")wd_upload(req, source, target = "")
req |
request handle obtained from |
source |
path to local file or directory |
target |
path to remote file or directory, if omitted the file or directory name will be used, if source is a file and target a directory then the file will be put into the target directory |
vector of uploaded files (invisibly)
## Not run: wd_upload(r, "d:/data/weather", "weatherfiles") wd_upload(r, "d:/data/abc.txt", "test/xyz.txt") wd_upload(r, "d:/data/abc.txt", "test") # uploaded file will be test/abc.txt ## End(Not run)## Not run: wd_upload(r, "d:/data/weather", "weatherfiles") wd_upload(r, "d:/data/abc.txt", "test/xyz.txt") wd_upload(r, "d:/data/abc.txt", "test") # uploaded file will be test/abc.txt ## End(Not run)