1

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?

lovelyvm
  • 127
  • 2
  • 16
  • 1
    Take a look at the `subprocess` module. Are you sure that you actually need wget at all? Why don't you implement it with pure Python and `urllib2` or `requests`? – Blender Jun 19 '13 at 03:31
  • Thanks!But can i also use urllib2 or requests in WxPython?'cause i don't have any idea on how to use it. Wget has an automatic downloading function and that's what i need in my download manager. – lovelyvm Jun 19 '13 at 04:25
  • Think about it the other way around. You need a downloading function and `wget` happens to do that. You can use just about anything with WxPython. – Blender Jun 19 '13 at 04:27
  • Is there any download manager that was created out of Wget and Python?I can't figure out on how to install and use [request]? – lovelyvm Jun 19 '13 at 06:03
  • I'm using Python 2.5, can i use urllib2 in 2.5? – lovelyvm Jun 19 '13 at 06:23
  • 1
    Why are you using Python 2.5? Upgrade to 2.7.5. – Blender Jun 19 '13 at 06:24

1 Answers1

1

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/

Mike Driscoll
  • 32,629
  • 8
  • 45
  • 88
  • Thank you so much for your help and suggestions. I'll try what you've just suggest. It's a great help. – lovelyvm Jun 21 '13 at 02:34
  • Can i still use python 2.5 and wxpython regarding with your suggestions? or do i need to upgrade it with 2.7 or up? – lovelyvm Jun 21 '13 at 02:48
  • How about if i'm going to make it automatic downloading, automatic in a way that your download will not stop unless you'll shut down your pc and if every time you'll turn on your pc it will download automatically. – lovelyvm Jun 21 '13 at 03:38
  • I also need to have a login with a username and password. An http and ftp textbox where you need to fill. And an output directory where you want to save your download file. How am i going to do this with python? – lovelyvm Jun 21 '13 at 03:57
  • Yes, you can use Python 2.5. To do the "automatic" stuff, you would have to save your progress information somewhere every so often and add your application as a start up application in Windows to get it to run on boot up. Try reading about dialogs for your login stuff. The text control has a style flag for passwords. You'll have to use the Save version of the FileDialog or possibly a DirDialog to specify the download location. – Mike Driscoll Jun 21 '13 at 13:12
  • Do i really need to have an ObjectListView or ListCtrl?What if i only have one ftp download url? And that url contains all the files do i need to add it to the ObjectListView or ListCtrl? – lovelyvm Jun 25 '13 at 02:51
  • You said you wanted a download manager and I thought that one of those widgets would be the best way to display the information. Feel free to use whatever widget you want. – Mike Driscoll Jun 25 '13 at 13:29
  • I found a wxpython download manager. The Kika gript that connects to an ftp site from zetcode. But when i tried to run the program, it says (11004, 'getaddrinfo failed'). What does it mean? And how am i going to fix it? – lovelyvm Jun 26 '13 at 03:20
  • How to add create a proxy setting in wxpython?and how am i going to relate my FTP/HTTP text control to the Username and Password text control? so that if everytime i'm going to login it will go to the window that has the actual content of an FTP/HTTP file, folder or site. – lovelyvm Jun 27 '13 at 08:40
  • You don't. You use Python for the proxy stuff. Try using Google more. See http://stackoverflow.com/questions/11726881/how-to-set-an-http-proxy-in-python-2-7. The user/password thing is a pop-up dialog. It isn't associated with anything except that you make it pop up in some event handler in your main app. In the dialog code, you can do all the authentication logic and make it complain if the user makes a mistake. In the main frame, you can tell your program to continue or bail depending on the result returned from the dialog. – Mike Driscoll Jun 27 '13 at 13:16
  • Thanks for the help. I'll search for more and try what you suggested. – lovelyvm Jun 28 '13 at 02:00
  • "Add your python C:\Python2x\Scripts to the path" - What does it mean?It's the 5th instruction in installing pip. – lovelyvm Jul 01 '13 at 03:41
  • I explain how to do this in the following tutorial: http://www.blog.pythonlibrary.org/2011/11/24/python-101-setting-up-python-on-windows/ – Mike Driscoll Jul 01 '13 at 13:29
  • What about downloading a **specific file type** using **VisualWget**? Is it possible to download only **mp3** files in a directory and its sub-directories in **VisualWget**? –  May 30 '20 at 07:15