Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copying file to sharepoint library in R

I am trying to copy files from a network drive location to a sharepoint library in R. The sharepoint library location requires user authentication and I was wondering how I can copy these files and pass authentication in code. A simple file.copy does not work. I was attempting to use the getURL() function from RCurl library but that hasn't worked either. I was wondering how I can accomplish this task - copying files while passing authentication.

Here are some code snippets that I have tried so far:

library(RCurl)
from <- "filename"
to <- "\\\\sharepoint.company.com\\Directory" #First attempt with just sharepoint location
to <- "file://sharepoint.company.com/Directory" #Another attempt with different format
h = getCurlHandle(header = TRUE, userpwd = "username:password")
getURL(to, verbose = TRUE, curl = h)
status <- file.copy(from, to)

Thank you!

like image 524
abhisarihan Avatar asked Apr 03 '13 22:04

abhisarihan


3 Answers

Not the most elegant solution but if you're looking to save into a single library on SharePoint, you can first map that library as a drive on your local machine.

Simply use setwd() to point to whatever drive letter you mapped the library to. You can then treat that Sharepoint library as if it were any other shared drive location, reading and writing files from/to it.

like image 163
duraq Avatar answered Sep 23 '22 01:09

duraq


I just use the following function to copy files to SharePoint. The only issue will be the file that was transferred will remain checked-out until the File is manually Checked-in for others to use.

 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")
like image 30
RanonKahn Avatar answered Sep 23 '22 01:09

RanonKahn


If you have SharePoint online, you can navigate to that library and click on the "Sync to Computer" button (has an icon with arrows and a computer). Then you can have this as a oneDrive and write directly to it.

like image 43
cluelessgumshoe Avatar answered Sep 21 '22 01:09

cluelessgumshoe