Hooray, this is just what I was hoping to find. Unfortunately, after customizing the script, I encountered the built-in error as the results… “Please check URL or Download Path!”
I went back and copied your example exactly and still get the same error.
Please replace “Prime” with your user account name in C:\Users\Prime\Downloads . if this still not resolve your problem , kindly share your URL link and Username to us. We will make it work for you.
Would it be possible to include a check that the download folder exists before starting the script? If it doesnt exist can it be created? Id like to use this to download a file in to a temp folder on the root of the C drive.
Would also be good to have a single script to just create a folder. That way the procedures could be linked.
This Script will allow you to Download file in specified path Eg:" ProgramaData\c1_temp\Downloads " because writing files in Temp folder may cause error. So, kindly please refer this Script
DownTo=r"<U+202A>C:\ProgramaData\c1_temp\Downloads" #Give your path here other than temp
URL='http://download.piriform.com/ccsetup523.exe' #Give url To download
import urllib
import os
if not os.path.exists(DownTo):
os.makedirs(DownTo)
def downloadFile(DownTo, fromURL):
try:
fileName = fromURL.split('/')[-1]
DownTo = os.path.join(DownTo, fileName)
with open(DownTo, 'wb') as f:
f.write(urllib.urlopen(fromURL).read())
if os.path.isfile(DownTo):
return '{} - {}KB'.format(DownTo, os.path.getsize(DownTo)/1000)
except:
return 'Please Check URL or Download Path!'
print downloadFile(DownTo, URL)
should it be URL or fromURL? It seems to differ in places. Also it reports a success when nothing happens. Ive also found that it can fail on trying to create a new directory. Does this support downloading files from https sites?
Yes, it supports downloading files from HTTPS sites.
It should be URL only, before giving URL ensure that the URL is working, means directly downloading the file.
Could you please tell me the path where you wanted to create Directory ?
This will definitely work. We are assigning URL value back to fromURL. ‘Finished success’ is your procedure ran status and we are printing ‘Please check URL or Download path’ if download not success in the execution logs.
This script support downloading files from https sites as well.
Ive tried several different folder locations, the default that you have in there, with the folder existing and without. Ive created new folders there and have left them. Also created a c: est folder on the root of the C drive and another on to a users desktop with no joy.
The file im downloading is a 2Gb zip from a digital ocean space (which is the same as S3). The link works fine if downloading via a browser.
Ive had it report successful multiple times and there are no files there.
Could you please provide us the link you tried to download and i damn sure creating directory is working perfectly from our side, Let me check again hope will reach you with better things.
Please refer this script it works perfect. Hope you will get satisfied with this.
path=r'C:\sss' #Give the path where you want to save
URL=r'http://download.piriform.com/ccsetup523.exe' #Give the download URL
def Download(path, URL):
import urllib2
import os
print "Download started"
fileName = URL.split('/')[-1]
fp = os.path.join(path, fileName)
request = urllib2.Request(URL, headers={'User-Agent' : "Magic Browser"})
parsed = urllib2.urlopen(request)
if os.path.exists(path):
print "Path already exists"
if not os.path.exists(path):
os.makedirs(path)
print "Path created"
with open(fp, 'wb') as f:
while True:
chunk=parsed.read(100*1000*1000)
if chunk:
f.write(chunk)
else:
break
print "The file downloaded successfully in specified path"
print fp
Download(path, URL)
@Aravind_pandi Now how about another one? Would it be possible to write a script that uses uses BITS to download a file… but… use BITS ability to throttle the download speed to xx mbps?