Skip to content

Instantly share code, notes, and snippets.

@gquere
Last active April 4, 2022 12:00
Show Gist options
  • Save gquere/c6c698e8e846583f7084392322a19aea to your computer and use it in GitHub Desktop.
Save gquere/c6c698e8e846583f7084392322a19aea to your computer and use it in GitHub Desktop.
Artifactory downloader
#!/usr/bin/env python3
import sys
import requests
import re
from packaging import version
# IGNORE SSL WARNING ###########################################################
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
# FOLDER UTILS #################################################################
def is_versions(folders):
for elem in folders:
if not re.match('[0-9.-]+-?.*/', elem):
return False
return True
def get_highest_version(folders):
for n, i in enumerate(folders):
folders[n] = version.parse(i)
return max(folders).public
# PARSE ########################################################################
def get_and_parse(url):
print(url)
r = SESSION.get(url, verify=False)
folders = []
files = []
for line in r.text.split('\n'):
href = re.search('href="(.*)"', line)
if not href:
continue
if href.group(1) == '../':
continue
if href.group(1)[-1] == '/':
folders.append(href.group(1))
else:
files.append(href.group(1))
if len(folders):
if is_versions(folders):
highest_version = get_highest_version(folders)
get_and_parse(url + highest_version)
else:
for folder in folders:
get_and_parse(url + folder)
for file in files:
if file.endswith('.jar'):
r = requests.get(url + file, verify=False)
with open(file, 'wb') as f:
f.write(r.content)
# MAIN #########################################################################
base_url = sys.argv[1]
SESSION = requests.session()
get_and_parse(base_url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment