Title: | Simple 'WebDAV' Client |
---|---|
Description: | A simple 'WebDAV' client that provides functions to fetch and send files or folders to a 'WebDAV' server. It does not support the full 'WebDAV' protocol. |
Authors: | Gunther Krauss [aut, cre] |
Maintainer: | Gunther Krauss <[email protected]> |
License: | GPL-2 |
Version: | 0.1.0 |
Built: | 2025-01-05 02:46:29 UTC |
Source: | https://github.com/gk-crop/rdav |
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.
Gunther Krauss
Useful links:
## Not run: # establish a connection, you will be asked for a password r <- wd_connect("https://example.com/remote.php/webdav/","exampleuser") # 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/webdav/","exampleuser") # 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, password = NULL)
wd_connect(url, username, password = NULL)
url |
url of the WebDAV directory |
username |
username |
password |
password - if not given, you will be asked for it |
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/webdav/","exampleuser") # establish a connection, use keyring package to retrieve the password keyring::key_set("mydav", "exampleuser") # call only once r <- wd_connect("https://example.com/remote.php/webdav/", "exampleuser" keyring::key_get("mydav", "exampleuser")) ## End(Not run)
## Not run: # establish a connection, you will be asked for a password r <- wd_connect("https://example.com/remote.php/webdav/","exampleuser") # establish a connection, use keyring package to retrieve the password keyring::key_set("mydav", "exampleuser") # call only once r <- wd_connect("https://example.com/remote.php/webdav/", "exampleuser" keyring::key_get("mydav", "exampleuser")) ## 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)
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)
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)