r - 如何使用 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文件夹复制的代码。我--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 应用程序注册
- 为应用注册添加权限
- 使用 cURL 获取“tenant_id”和“resource_id”
- 对 API 进行 get/post 调用
它都在包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)
推荐阅读
- java - 如何使用本身加密的私钥/密码加密数据?
- firebase - Cloud Functions bucket.upload() 根本没有运行
- matlab - 创建重叠时间间隔的最佳选择
- c++ - “Python 异常
没有名为 _M_dataplus 的成员。”尝试打印字符串时 - python - Prim 算法替代方案
- excel - 如何根据工作表名称的内容创建一键宏以对选项卡进行颜色编码?
- rust - Rust 不打印到终端
- angular - 如何在 Angular Firestore 中将日期保存为时间戳?
- amazon-dynamodb - DynamoDB 如果属性不存在,则在 node.js 中创建它
- python - 如何将不同长度的时间窗口应用于熊猫数据框