Last active
August 29, 2015 14:11
-
-
Save eahrold/6148322036614bcd9b07 to your computer and use it in GitHub Desktop.
Test POST to your JDS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/usr/bin/python | |
''' if you don't have the requests module installed you'll need to do that | |
with either pip or easy_install''' | |
import os,requests | |
''' Setup server and auth data. This is the name of your JSS, | |
NOT the webdav share of the JDS. The JSS actually distributes the | |
data you upload to it across the JDS shares. | |
''' | |
server = 'https://pretendco.jamfcloud.com' | |
username = 'myusername' | |
password = 'mypassword' | |
# strip off trailing "/" characters from server | |
server = server.rstrip('/') | |
# construct the session elements | |
filename = '/tmp/test.txt' | |
resource = open(filename, 'a+rb') | |
basefname = os.path.basename(filename) | |
headers = {'DESTINATION': '1', 'OBJECT_ID': str(-1), 'FILE_TYPE':0, 'FILE_NAME': basefname} | |
jds_upload_url = '%s/dbfileupload' % server | |
# create the session and post | |
session = requests.session() | |
session.auth = (username, password) | |
response = session.post(url=jds_upload_url, data=resource, headers=headers) | |
# clean up, close our FD | |
resource.close() | |
# print out the response | |
print "Response: %s\n" % response | |
print "Response Text: %s\n" % response.text | |
print "Response Headers: %s\n" % response.headers | |
print "Response History: %s\n" % response.history |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment