I need to upload files from Unix directory into SharePoint 2010. This has turned out to be a mountain that I am having significant difficulty climbing, please assist, sample codes will be appreciated. My options are to use either a bash script, java or python code to get this working. A bonus would be also copy files from SharePoint back to Unix.



Haven't tested it myself yet, but this seems to be promising for python: sharepy

There is an example about how to download a file.

If server-side javascript is an option, I would recommend request-sp. I make most calls with it and authentication is supplied by username:password.

Most file operations can be done with the REST interface of SharePoint. As you said, authentication can be a bit tricky.

You can upload a file by POST-ing to this url


You have to add your file to the buffer of the POST-request.

Additional properties could be set with a merge request, but I have never done that so I am not sure about it.


SharePoint provides web services. Your case you can use Copy service end point.

Here is an example of how to do this in Java http://www.javaworld.com/article/2078906/enterprise-java/java-tip-consuming-sharepoint-web-services-with-a-java-client.html

protected  void uploadDocument(CopySoap port, String sourceUrl)   throws Exception {

    File f = new File(sourceUrl);
    logger.debug("Uploading: " + f.getName());

    String url = getProperties().getProperty("copy.location") + f.getName();
    DestinationUrlCollection destinationUrlCollection = new DestinationUrlCollection();
    if(getProperties().getProperty("copy.location2") != null){
         url = getProperties().getProperty("copy.location2") + f.getName();

    FieldInformation titleFieldInformation = new FieldInformation();

    FieldInformationCollection fields = new FieldInformationCollection();

    CopyResultCollection results = new CopyResultCollection();
    Holder resultHolder = new Holder(results);
    Holder longHolder = new Holder(new Long(-1));

    //make the call to upload
    port.copyIntoItems(sourceUrl, destinationUrlCollection, fields, readAll(f), longHolder,resultHolder);

    //does not seem to change based on different CopyResults
    logger.debug("Long holder: " + longHolder.value);

    //do something meaningful here
    for (CopyResult copyResult : resultHolder.value.getCopyResult()) {              
        logger.debug("Destination: " + copyResult.getDestinationUrl());
        logger.debug("Error Message: " + copyResult.getErrorMessage());
        logger.debug("Error Code: " + copyResult.getErrorCode());
        if(copyResult.getErrorCode() != CopyErrorCode.SUCCESS)
            throw new Exception("Upload failed for: " + copyResult.getDestinationUrl() + " Message: " 
                    + copyResult.getErrorMessage() + " Code: " +   copyResult.getErrorCode() );

  • 1
    how should I handle SharePoint authentication since I will be running this script from unix? – Bob Ezuba Apr 7 '15 at 14:06
  • Its explained in the article. There is a sample source code available which you can try. – Amal Hashim Apr 7 '15 at 14:09

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.