views:

578

answers:

4

Trying to implement a progress dialog window for file uploads that look like a cross between IE download dialog and Firefox download dialog with a python GUI library on Windows.

  1. What asynchronous (S)FTP libraries are there for python? Ideally I should be able to do file upload resumes and track the progress of each parallel file uploads.
  2. If I'm running each file upload in a separate process each, how would I get the upload status and display it in a progress bar dialog?
+1  A: 

"ftplib" is the standard ftp library built in to Python. In Python 2.6, it had a callback parameter added to the method used for uploading.

That callback is a function you provide to the library; it is called once for every block that is completed.

Your function can send a message to the GUI (perhaps on a different thread/process, using standard inter-thread or inter-process communications) to tell it to update its progress bar.

Reference

Oddthinking
Let's say I can't use a python version greater than 2.5, what are my options then for passing a callback parameter?
TheObserver
Not so good. IIRC, the callback for *download* was added in 2.5.2 (perhaps earlier?) but wasn't added to the *upload* until 2.6.(See also separate answer for ckftp2.)
Oddthinking
+1  A: 

If you want a complete example of how to use threads and events to update your GUI with long running tasks using WxPython have a look at this page. This tutorial is quite useful and helped me perform a similar program than yours.

Mapad
+1  A: 

If you data transfer runs in a separate thread from the GUI, you can use wx.CallAfter() whenever you have to update you progress bar from the data transfer thread.

First, using CallAfter() is mandatory as wxPython function cannot be called from child threads.

Second, this will decouple the execution of the data transfer from the GUI in the main thread.

Note that CallAfter() only works for threads, not for separate processes. In that case, using the multiprocessing package should help.

Ber
A: 

If you can't use Python 2.6's ftplib, there is a company offering a commercial solution.

Chilkat's CKFTP2 costs several hundreds of dollars, but promises to work with Python 2.5, and offers a function call get_AsyncBytesSent() which returns the information you need. (I didn't see a callback, but it may offer that too.)

I haven't used this product.

Also consider that if FTP proves to be too hard/expensive, you could always switch to HTTP uploads instead. Chilkat have a free HTTP/HTTPS upload library.

Oddthinking