Created
January 14, 2019 16:21
-
-
Save int0x33/27440f1a1abb71b9b15b90e1eddcb694 to your computer and use it in GitHub Desktop.
Me eatz all da filez
This file contains hidden or 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/env python | |
import subprocess | |
import os.path | |
import sys | |
import urllib2 | |
from xml.etree.ElementTree import parse | |
def main(): | |
#First let's request and save the AWS XML | |
xml = getXML() | |
#Now let's parse the XML | |
parseXML(xml) | |
def getXML(): | |
#Make the request | |
response = urllib2.urlopen(sys.argv[1]) | |
xml = response.read() | |
#If we have an old file, remove it | |
if os.path.isfile('data.xml'): | |
os.remove('data.xml') | |
#Save XML | |
with open('data.xml', 'a') as f: | |
f.write(xml) | |
#Return the parsed document | |
doc = parse('data.xml').getroot() | |
return doc | |
def parseXML(xml): | |
#Loop though files found and request download | |
for child in xml: | |
for contents in child[:1]: | |
#We just need the key to download the file | |
key = contents.text | |
downloadFile(key) | |
def downloadFile(key): | |
#Download file with bucket url that is passed to script with the key appended | |
cmd = 'wget '+sys.argv[1]+key | |
#We launch a wget subprocess here | |
subprocess.call(cmd, shell=True) | |
if __name__=='__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment