# Download document from SharePoint (NTLM Authentication)

**URL:** <https://forum.inductiveautomation.com/t/download-document-from-sharepoint-ntlm-authentication/69474>\
**Category:** Ignition\
**Tags:** python, scripting\
**Created:** [February 6, 2023, 10:50am UTC](https://forum.inductiveautomation.com/t/download-document-from-sharepoint-ntlm-authentication/69474 "2023-02-06T10:50:55Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![ryanjmclaughlin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryanjmclaughlin/32/4318_2.png) [@ryanjmclaughlin](https://forum.inductiveautomation.com/u/ryanjmclaughlin)\
**Post date:** [February 11, 2023, 11:04pm UTC](https://forum.inductiveautomation.com/t/download-document-from-sharepoint-ntlm-authentication/69474/7 "2023-02-11T23:04:56Z")

</div>

Here is what I use, can work for files just need to modify the return...

```auto
def httpGetNTLM(url):
	from org.apache.http.auth import AuthScope
	from org.apache.http.auth import NTCredentials
	from org.apache.http.client.methods import HttpGet
	from org.apache.http.impl.client import DefaultHttpClient
	from org.apache.http.impl.client import BasicResponseHandler
	from org.apache.http.entity import ContentType
	from java.io import ByteArrayOutputStream
	
	# Setup the client with NTLM Auth
	httpclient = DefaultHttpClient()
	
	# Define the credentials to use
	creds = NTCredentials(username, password, system.net.getHostName(), "DOMAIN")
	httpclient.getCredentialsProvider().setCredentials(AuthScope.ANY, creds)
	
	# Define the host and URL to call
	httpget = HttpGet(url)
	
	# Execute the request
	response = httpclient.execute(httpget)
	
	# Get response entity and MIME type
	entity = response.getEntity()
	contentType = ContentType.getOrDefault(response.getEntity()).getMimeType().lower()
	
	# Return the result
	if 'json' in contentType:
		return system.util.jsonDecode(BasicResponseHandler().handleResponse(response))
	elif contentType in ["image/png", "image/jpeg"]:
		baos = ByteArrayOutputStream()
		entity.writeTo(baos)
		return baos.toByteArray(), contentType
	else:
		return BasicResponseHandler().handleResponse(response), contentType

```

---

_[View the full topic](https://forum.inductiveautomation.com/t/download-document-from-sharepoint-ntlm-authentication/69474)._
