import httplib
import re
import os
conn = httplib.HTTPSConnection("af.hikvision.com.cn")
def downloadDstFile(dirName,fileName,fullUrl):
print "start down load file ",fileName,fullUrl
conn.request("GET", fullUrl)
fileDataResponse = conn.getresponse()
with open(os.path.join(dirName,fileName),"wb") as f:
f.write(fileDataResponse.read())
def getFullDirToLocal(rootUrl,rootDir):
conn.request("GET", rootUrl)
response = conn.getresponse().read()
subUrls = re.findall(r'<a.*?href="(.*?)">(.*?)</a>', response)
for singleUrl in subUrls:
if singleUrl[1] != "../":
if singleUrl[1][-1] != "/":
downloadDstFile(rootDir,singleUrl[1],rootUrl+singleUrl[1])
else:
if not os.path.exists(rootDir+singleUrl[1]):
os.mkdir(rootDir+singleUrl[1])
getFullDirToLocal(rootUrl+str(singleUrl[1]),rootDir+singleUrl[1])
getFullDirToLocal("/artifactory/list/sbmc-release/public-lib/","./")