[英]how to download files from a sharepoint folder with R
我公司的 sharepint 文件夹中有一些文件。 我需要使用 r 下载该文件夹中的所有文件。 我怎么能用 R 做到这一点?
我用谷歌搜索了这个问题并得到了这个链接。 这是关于将文件上传到共享点文件夹。 [ 将文件从 R 上传到 SharePoint
链接中的代码如下所示:
saveToSharePoint <- function(fileName)
{
cmd <- paste("curl --max-time 7200 --connect-timeout 7200 --ntlm --user","username:password",
"--upload-file /home/username/FolderNameWhereTheFileToTransferExists/",fileName,
"teamsites.OrganizationName.com/sites/PageTitle/Documents/UserDocumentation/FolderNameWhereTheFileNeedsToBeCopied/",fileName, sep = " ")
system(cmd)
}
saveToSharePoint("SomeFileName.Ext")
这是关于上传一个特定文件。 但我需要的是从 sharepoint 文件夹下载文件。
所以,我修改了代码以从 sharepoint 文件夹复制。 我将--upload-file
更改为--download-file
。
copyFromSharePoint <- function(fileName)
{
cmd <- paste("curl --max-time 7200 --connect-timeout 7200 --ntlm --user","username:password",
"--download-file teamsites.OrganizationName.com/sites/PageTitle/Documents/FolderNameWhereTheFileToTransferExists/",fileName,
"home/username/UserDocumentation/FolderNameWhereTheFileNeedsToBeCopied/",fileName, sep = " ")
system(cmd)
}
copyFromSharePoint("SomeFileName.Ext")
但是,这似乎不起作用。 错误信息如下:
curl: option --download-file: is unknown
有谁知道我如何用 R 做到这一点?
另外,如果我需要下载文件夹中的所有文件,而不是某个特定文件怎么办。有谁知道我如何用 R 来做到这一点?
我制作了一个名为sharepointr的简单 R 包来从 SharePoint 上传和下载文件。
我从 R 进行整个下载/上传到 sharepoint 工作的方式是:
这一切都在包Readme.md 中描述
# Installing the package
install.packages("devtools")
devtools::install_github("esbeneickhardt/sharepointr")
# Setting parameters
client_id <- "insert_from_first_step"
client_secret <- "insert_from_first_step"
tenant_id <- "insert_from_fourth_step"
resource_id <- "insert_from_fourth_step"
site_domain <- "yourorganisation.sharepoint.com"
sharepoint_url <- "https://yourorganisation.sharepoint.com/sites/MyTestSite"
# Getting a SharePoint Token
sharepoint_token <- get_sharepoint_token(client_id, client_secret, tenant_id, resource_id, site_domain)
# Getting sharepoint digest value
sharepoint_digest_value <- get_sharepoint_digest_value(sharepoint_token, sharepoint_url)
# Downloading a file
sharepoint_path <- "Shared Documents/test"
sharepoint_file_name <- "Mappe.xlsx"
out_path <- "C:/Users/User/Desktop/"
download_sharepoint_file(sharepoint_token, sharepoint_url, sharepoint_digest_value, sharepoint_path, sharepoint_file_name, out_path)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.