DingleBerries Posted April 9, 2009 Share Posted April 9, 2009 I am looking for the simplest way to download a file from a web site. The user will tell the program where it is and then I need python to work its magic. Fewer lines of code the better. Thank in advance. Quote Link to comment Share on other sites More sharing options...
ls Posted April 10, 2009 Share Posted April 10, 2009 import urllib2 url = raw_input("Url : ") outputname = url.split('/')[-1] outputname = open(outputname,'w') for line in urllib2.urlopen(url).readlines(): outputname.write(line) outputname.close() print "Done" With this code you can download from http and from ftp you can find more info here: http://docs.python.org/library/urllib.html Quote Link to comment Share on other sites More sharing options...
sablefoxx Posted April 10, 2009 Share Posted April 10, 2009 damn 8 lines, impressive Quote Link to comment Share on other sites More sharing options...
Zimmer Posted April 10, 2009 Share Posted April 10, 2009 sablefoxx how about three import urllib url=raw_input('URL: ') urllib.retrieve(url, filename='C:\\Documents and Settings\\file_download') Quote Link to comment Share on other sites More sharing options...
DingleBerries Posted April 10, 2009 Author Share Posted April 10, 2009 I found what i needed.. sort of import urllib urllib.urlretrieve('http://downloads.sourceforge.net/vnc-tight/tightvnc-1.3.10-setup.exe','tightvnc-1.3.10-setup.exe') What I am trying to do is to have a server respond to a command like, download file.com/here.ext but im having trouble with if command == "download ":, it will not respond to it if there is more after download and * doesnt work. This is what I am working with atm: elif command == download: download = "download " + * download = s.replace('download ','') urllib.urlretrieve(download,'whateve.pc') EDIT GOT IT elif command.startswith("download") file = command.replace('download ','') urllib.urlretrieve(download,'file') Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.