Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am fairly new to python and seek guidance for a question which might sound trivial to many. Is there a way to use 'wget' in a python script to download raster files from a server and process them in the same script?

share|improve this question
up vote 13 down vote accepted

Python has urllib2 built-in, which opens a file-pointer-like object from a IP resource (HTTP, HTTPS, FTP).

import urllib2, os

# See
rast_url = ''
infp = urllib2.urlopen(rast_url)

You can then transfer and write the bytes locally (i.e., download it):

# Open a new file for writing, same filename as source
rast_fname = os.path.basename(rast_url)
outfp = open(rast_fname, 'wb')

# Transfer data .. this can take a while ...

print('Your file is at ' + os.path.join(os.getcwd(), rast_fname))

Now you can do whatever you want with the file.

share|improve this answer
+1 It may seem slightly more complicated to do it this way but it will be more portable and be easier to debug because you don't have external dependencies. – Sean Aug 19 '11 at 13:41

A couple of ways to accomplish this. You can use the subprocess module to call wget - see

import subprocess

retcode =["wget", args])

Or you can use python to download the file directly using the urllib (or urllib2) module - There are examples in the documentation.

share|improve this answer

In this previous answer is a method using a call to os.system.

os.system('wget %s' % (fullurl))
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.