1

I am trying to upload an image to a SharePoint Online Document Library using curl.

This is the command I use:

curl --ntlm --user user@domain.com:password --upload-file test.docx https://contoso.sharepoint.com/sites/mysite/leansite/TestDoc/test.docx -verbose

Where the Document Library is TestDoc.

I am getting 401 Unauthorized exception. I think maybe -ntlm is not liked by SP Online.

Is Claims-Based Auth supported in curl? I think this maybe the cause.

*   Trying ip...
* TCP_NODELAY set
* Connected to contoso.sharepoint.com (ip) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
*   CAfile: C:\Contoso\PAL\curl-7.52.1-win32-mingw\curl-7.52.1-win32-mingw\bin\curl-ca-bundle.crt
  CApath: none
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Client hello (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-SHA384
* ALPN, server did not agree to a protocol
* Server certificate:
*  subject: C=US; ST=WA; L=Redmond; O=Microsoft Corporation; OU=Microsoft Corporation; CN=*.sharepoint.com
*  start date: Feb 23 19:42:10 2016 GMT
*  expire date: Feb 22 19:42:10 2018 GMT
*  subjectAltName: host "contoso.sharepoint.com" matched cert's "*.sharepoint.com"
*  issuer: C=US; ST=Washington; L=Redmond; O=Microsoft Corporation; OU=Microsoft IT; CN=Microsoft IT SSL SHA2
*  SSL certificate verify ok.
* Server auth using NTLM with user 'user@domain.com'
> PUT /sites/Maynilad/leansite/TestDoc/test.docx HTTP/1.1
> Host: contoso.sharepoint.com
> Authorization: NTLM TlRMTVNTUAABAAAAB4IIogAAAAAAAAAAAAAAAAAAAAAKADk4AAAADw==
> User-Agent: curl/7.52.1
> Accept: */*
> Referer: rbose
> Content-Length: 0
>
< HTTP/1.1 401 Unauthorized
< Server: Microsoft-IIS/8.5
< WWW-Authenticate: NTLM TlRMTVNTUAACAAAADAAMADgAAAAFgomihBuCtJg24sMAAAAAAAAAAPIA8gBEAAAABgOAJQAAAA9ZAEwATwAwADAAMQACAAwAWQBMAE8AMAAwADEAAQAeAFUAUwBSADEANQA3ADEANQA4ADEANQAtADIANgA0AAQALABZAEwATwAwADAAMQAuAE0AUwBPAFAAUgBEAC4ATQBTAEYAVAAuAE4ARQBUAAMATABVAFMAUgAxADUANwAxADUAOAAxADUALQAyADYANAAuAFkATABPADAAMAAxAC4ATQBTAE8AUABSAEQALgBNAFMARgBUAC4ATgBFAFQABQAsAFkATABPADAAMAAxAC4ATQBTAE8AUABSAEQALgBNAFMARgBUAC4ATgBFAFQABwAIAKGzFCrTcNIBAAAAAA==
< SPRequestGuid: 32f2cb9d-d031-3000-bd41-8829cb9968bc
< request-id: 32f2cb9d-d031-3000-bd41-8829cb9968bc
< Strict-Transport-Security: max-age=31536000
< X-FRAME-OPTIONS: SAMEORIGIN
< SPRequestDuration: 4
< SPIisLatency: 2
< X-Powered-By: ASP.NET
< MicrosoftSharePointTeamServices: 16.0.0.6105
< X-Content-Type-Options: nosniff
< X-MS-InvokeApp: 1; RequireReadOnly
< P3P: CP="ALL IND DSP COR ADM CONo CUR CUSo IVAo IVDo PSA PSD TAI TELo OUR SAMo CNT COM INT NAV ONL PHY PRE PUR UNI"
< Date: Tue, 17 Jan 2017 15:05:38 GMT
< Content-Length: 0
<
* Curl_http_done: called premature == 0
* Connection #0 to host contoso.sharepoint.com left intact
* Issue another request to this URL: 'https://contoso.sharepoint.com/sites/Maynilad/leansite/TestDoc/test.docx'
* Found bundle for host contoso.sharepoint.com: 0x33d88c8 [can pipeline]
* Re-using existing connection! (#0) with host contoso.sharepoint.com
* Connected to contoso.sharepoint.com (ip) port 443 (#0)
* Server auth using NTLM with user 'user@domain.com'
> PUT /sites/mysite/leansite/TestDoc/test.docx HTTP/1.1
> Host: contoso.sharepoint.com
> Authorization: NTLM TlRMTVNTUAADAAAAGAAYAJwAAAB6AXoBtAAAAAAAAABYAAAAMgAyAFgAAAASABIAigAAAAAAAAAuAgAABYKIogoAOTgAAAAPCXakIO68kku98ZzxgDsBa0wAZQBhAG4AQABjAGwAaQBuAGsAaQB0AHMAbwBsAHUAdABpAG8AbgBzAC4AYwBvAG0ATABFAEEATgAtAEQARQBMAEwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPkUT7d53BAivjcEqnWQnMQEBAAAAAAAAobMUKtNw0gFseLkaGI+DNAAAAAACAAwAWQBMAE8AMAAwADEAAQAeAFUAUwBSADEANQA3ADEANQA4ADEANQAtADIANgA0AAQALABZAEwATwAwADAAMQAuAE0AUwBPAFAAUgBEAC4ATQBTAEYAVAAuAE4ARQBUAAMATABVAFMAUgAxADUANwAxADUAOAAxADUALQAyADYANAAuAFkATABPADAAMAAxAC4ATQBTAE8AUABSAEQALgBNAFMARgBUAC4ATgBFAFQABQAsAFkATABPADAAMAAxAC4ATQBTAE8AUABSAEQALgBNAFMARgBUAC4ATgBFAFQABwAIAKGzFCrTcNIBBgAEAAIAAAAIADAAMAAAAAAAAAAAAAAAADAAAK18CI9jD04glSs15ZOtvhr5xAix32o2pTP80JxFY/pyCgAQAAAAAAAAAAAAAAAAAAAAAAAJAAAAAAAAAAAAAAAAAAAA
> User-Agent: curl/7.52.1
> Accept: */*
> Referer: rbose
> Content-Length: 11272
> Expect: 100-continue
>
< HTTP/1.1 401 Unauthorized
< Server: Microsoft-IIS/8.5
< SPRequestGuid: 32f2cb9d-5046-3000-bd41-8e88997aa3bc
< request-id: 32f2cb9d-5046-3000-bd41-8e88997aa3bc
< Strict-Transport-Security: max-age=31536000
< X-FRAME-OPTIONS: SAMEORIGIN
< SPRequestDuration: 7
< SPIisLatency: 1
* NTLM handshake rejected
* Authentication problem. Ignoring this.
< WWW-Authenticate: NTLM
< X-Powered-By: ASP.NET
< MicrosoftSharePointTeamServices: 16.0.0.6105
< X-Content-Type-Options: nosniff
< X-MS-InvokeApp: 1; RequireReadOnly
< P3P: CP="ALL IND DSP COR ADM CONo CUR CUSo IVAo IVDo PSA PSD TAI TELo OUR SAMo CNT COM INT NAV ONL PHY PRE PUR UNI"
< Date: Tue, 17 Jan 2017 15:05:38 GMT
< Content-Length: 0
* HTTP error before end of send, stop sending
<
* Curl_http_done: called premature == 0
* Closing connection 0
* TLSv1.2 (OUT), TLS alert, Client hello (1):
2

Nope, NTLM is not supported for SharePoint Online. Instead you could consider either Claims-Based Identity (SAML) or OAuth flow.

For implementation details you could refer to phpSPO library (which in turn utilizes cURL library), in particular:

Disclaimer: I'am an original author of this library

  • Thanks for this, looks intuitive and better suited for Sharepoint. Is this available for scripting (ex. run on a daily basis?)? – Water Jan 18 '17 at 1:54
  • I am currently trying it out but am encountering difficulties. I am receiving Uncaught Error: Class 'AuthenticationContext' not found in test.php. But I have defined require_once on the top of my php script. <?php require_once './vendor/autoload.php'; ?> – Water Jan 18 '17 at 3:35
  • I have included necessary use now. It says File Uploaded successfully , but when I look at the DocLibrary, it isn't there. There is no error message also. – Water Jan 18 '17 at 4:32
  • @Water, for a script based solution, would it be an option to consider to switch to PowerShell, like explained in this post – Vadim Gremyachev Jan 18 '17 at 8:31
  • 1
    Yes Vadim, I have tried it and it worked. Thanks! I am just wondering, the earlier code you gave me is the saveFile method. What is the difference between the 2? After this, I will mark you as answer :) – Water Jan 18 '17 at 9:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.