-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathfile_upload.py
30 lines (23 loc) · 962 Bytes
/
file_upload.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"""Upload data to the MinXSS team"""
__authors__ = "James Paul Mason"
__contact__ = "[email protected]"
import os
import requests
from logger import Logger
def upload(filename):
log = Logger().create_log()
url = 'http://lasp.colorado.edu/minxss/beacon/fileupload.php'
filename = ensure_slashes_compliant_with_server(filename)
file_to_send = {'filename': (filename, open(filename, 'rb'))}
if os.path.getsize(filename) > 0:
r = requests.post(url, files=file_to_send)
print(r.text)
if r.status_code == 200:
log.info('Successfully uploaded data to MinXSS team.')
log.info(r.text)
else:
log.error('Failed to upload data to MinXSS team. Requests error {}'.format(r.status_code))
else:
log.info('Not uploading because data file is empty.')
def ensure_slashes_compliant_with_server(filename):
return filename.replace('\\', '/')