Jump to content

Download a file[Python]


Recommended Posts

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

Link to comment
Share on other sites

damn 8 lines, impressive

Link to comment
Share on other sites

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')

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...