简体   繁体   中英

Wget and Python download manager?

I'm having difficulties with python download manager. I already tried downloading with only wget and it worked. I also created my wxpython interface. But my problem now is how will I combine the two? How am I going to add the wget downloading code to my wxpython interface and make it work? Is it possible to combine wget with python to come up with a download manager, such as winwget or visualwget?


import os
from ftplib import FTP

ftp = FTP("ftpsite","username", "password")
ftp.login()
ftp.retrlines("LIST")

ftp.cwd("folderOne")
ftp.cwd("subFolder")

listing = []
ftp.retrlines("LIST", listing.append)
words = listing[0].split(None, 8)
filename = words[-1].lstrip()

#download the file
local_filename = os.path.join(r"C:\example", file)
lf = open(local_filename, "wb")
ftp.retrbinary("RETR " + filename, lf.write, 8*1024)
lf.close()

I've tried this code it's from your blog. But it says,

Traceback (most recent call last):
  File "directory", line 4, in <module>
    ftp = FTP("ftp://samoa.gsfc.nasa.gov/site/", "user", "password")
  File "C:\Python27\lib\ftplib.py", line 117, in __init__
    self.connect(host)
  File "C:\Python27\lib\ftplib.py", line 132, in connect
    self.sock = socket.create_connection((self.host, self.port), self.timeout)
  File "C:\Python27\lib\socket.py", line 553, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
gaierror: [Errno 11004] getaddrinfo failed

What's wrong with the codes?

All you need to do is use event handlers. For example, you could have a text control where you copy and paste the download URL. Then you would have a button to add that download to a ListCtrl or better, an ObjectListview widget. Now you have a way of showing a list of downloads.

You could start the download when you add the item or start all the downloads with a separate button. Or you could use the second button to download stuff in order instead of in parallel. Since downloading a file is a long running process, you'll want to do the downloading part inside a thread. You should check out one of the following links for details on that:

You might also find this simple downloading example useful: http://wiki.wxpython.org/DownloadWidget

This old thread also addresses some of your questions: http://wxpython-users.1045709.n5.nabble.com/wxPython-Python-equivalent-to-wget-lt-url-gt-td2358484.html

And then there's this tutorial on just downloading files with Python: http://www.blog.pythonlibrary.org/2012/06/07/python-101-how-to-download-a-file/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM