Link to home
Start Free TrialLog in
Avatar of boukaka
boukakaFlag for Canada

asked on

Python 3 script to upload files to sharepoint 2010

I need a python 3 script to upload files to sharepoint 2010. I can't find anything that works because apparently REST api doesn't work for 2010.
Avatar of noci
noci

Did you try the WEBDAV route?
Avatar of boukaka

ASKER

I'm looking at that but I can't seem to find any examples where it interacts with a sharepoint server. I'm looking for an example script to start from, do you know of one? I'm fairly new to Python.
Pypi is a nice source to look around:   https://pypi.org/project/webdavclient/
There also is a sharepoint access module, not sure it that uses the REST Api though.   https://pypi.org/project/sharepoint/
Avatar of boukaka

ASKER

I have found a Powershell solution that works - I wish it was in python - does anyone know how to convert this?

# Set the variables
$destination = "http://portal.contoso.com/sites/stuff/Docs” 
$File = get-childitem “C:\Docs\stuff\Secret Sauce.docx”

# Since we’re doing this remotely, we need to authenticate
$securePasssword = ConvertTo-SecureString "pass@word1" -AsPlainText -Force
$credentials = New-Object System.Management.Automation.PSCredential ("contoso\johnsmith", $securePasssword)

# Upload the file
$webclient = New-Object System.Net.WebClient
$webclient.Credentials = $credentials
$webclient.UploadFile($destination + "/" + $File.Name, "PUT", $File.FullName)
ASKER CERTIFIED SOLUTION
Avatar of noci
noci

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of boukaka

ASKER

Fantastic, thank you!