Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I want to download a file from a SharePoint server (url).
I manage to download it using Firefox.
I can't manage to download it using curl.

Sounds surprising, but the same URL works on Firefox, fails with curl.

Works on Firefox:

Actually, entering the URL initiates an authentication conversation between client and server, with in total 4 requests sent by Firefox:

enter image description here

  • Initial request: The one I typed the URL into the browser: https://mycorp.raxsp.com/_windows/default.aspx?ReturnUrl=/personal/mycorp_user1/_vti_bin/cmis/rest?getRepositories. It asked me for a user/password, so I entered it and validated. Response contains a WWW-Authenticate header with value NTLM
  • Request 2: Same URL, but this time with an NTLM autorization token in the request headers.
  • Request 3: Same, but this time the NTLM authorization token is the one found in the response header of request 2.
  • Request 4: To https://mycorp.raxsp.com/personal/mycorp_user1/_vti_bin/cmis/rest?getRepositories, download is successful.

Fails with curl:

With curl, the request below results in 401 Unauthorized:

curl -i -u mycorp.user1@raxsp.com:mypass 'https://mycorp.raxsp.com/_windows/default.aspx?ReturnUrl=/personal/mycorp_user1/_vti_bin/cmis/rest?getRepositories'

Thinking I had to run the 4 requests like Firefox, I tried to add all 4 URLs to the curl command line, but that results in 401 Unauthorized for the first three and 403 FORBIDDEN for the last:

curl -i -u mycorp.user1@raxsp.com:mypass 'url1' 'url2' 'url3' 'url4'

Conclusion

How to download the file without Firefox (from command-line)?
I am not limited to curl, any tool or programming language is fine too.

share|improve this question

put on hold as off-topic by Jenny D, masegaloeh, 84104, mdpc, Hyppy Apr 22 at 14:31

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions on Server Fault must be about managing information technology systems in a business environment. Home and end-user computing questions may be asked on Super User, and questions about development, testing and development tools may be asked on Stack Overflow." – Jenny D, masegaloeh, 84104, mdpc, Hyppy
If this question can be reworded to fit the rules in the help center, please edit the question.

    
Is it the remote site or an intermediate proxy which is issuing the NTLM challenge? –  symcbean Apr 2 '13 at 16:28
    
@symcbean: I believe it is the remote site. Maybe Rackspace is placing some sort of proxy before the real server, but it looks like direct access. –  Nicolas Raoul Apr 3 '13 at 1:56
    
did you try to extract cookies from firefox and provide them to curl ? –  neutrinus Oct 16 '14 at 6:24

1 Answer 1

cURL supports NTLM authentication, you should investigate these switches:

http://curl.haxx.se/docs/manpage.html#--ntlm (--ntlm)

http://curl.haxx.se/docs/manpage.html#--anyauth (--anyauth)

At a guess, something along the lines of:

curl 'https://mycorp.raxsp.com/_windows/default.aspx?ReturnUrl=/personal/mycorp_user1/_vti_bin/cmis/rest?getRepositories' -ntlm -u username:password
share|improve this answer
    
--ntlm sounds great but unfortunately Sharepoint gives 500 Internal Server Error at the second step (a problem Firefox does not run into, somehow). Same with --anyauth. –  Nicolas Raoul Apr 2 '13 at 12:36

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