views:

206

answers:

2

I'm looking for a good, high-level python ftp client/server library. I'm working on a project that has "evolved" a small http/ftp library on top of ftplib/urllib/urllib2 from what was originally one function, and almost none of it was designed to be built upon. So now it's time to refactor kind of seriously, and I'd like to just switch to a library. The thing I'd most like to not deal with is robust-retry logic (like, keep retrying 15 times, or keep retrying until 12pm).

The problem that we've got right now is that we have about 10 separate grab() and put() functions. Aesthetically speaking, I'd rather have one of each with optional arguments along the lines of try_until=datetime(2009, 10, 7, 19) or retrys=15. We work with both binary and text data, so the functions would have to be reasonably smart about that. And we do way more grabbing than putting, so I can deal without the puts.

urlgrabber looks like exactly what I want, but there doesn't seem to have been any development for the last couple years and I'm not sure how compatible it is with 2.6. Anybody got much experience with this? Or opinions?

+4  A: 

URLgrabber appears to be very mature, and since it's used by yum (and thus many Unix systems), I would expect it to be very stable. Python 2.x is largely backward compatible. You might encounter some warnings, but I would expect it to work suitably under Python 2.6.

Jason R. Coombs
Yep, I've been testing it and it *seems* to work fine, but I'm a little nervous. And I'm also a little surprised that something that's core to YUM hasn't had a single commit in 2 years. Unless I'm looking at the wrong repository, but I can't find any other ones.
quodlibetor
It doesn't matter *that much* whether a project has recent commits. Many mature projects reach a level of stability, where the features are complete and the bugs have been squashed.
bigmattyh
This has been working for me for the last few weeks, so: awesome.
quodlibetor
A: 

Depending on the sort of application you are writing, you might want to consider twisted python, as it has http server and client code built in. However, it is a rather large departure from standard procedural python programming.

The big advantage of twisted for you is that it can handle your client requests in the background, handles retries and is very scalable.

Update

For a quick script that interacts with servers, see this serverfault answer: http://serverfault.com/questions/66336/script-automation-login-enter-password-run-commands-save-output-locally

It recomends the tool expect

Expect is a tool for automating interactive applications such as telnet, ftp, passwd, fsck, rlogin, tip, etc. Expect really makes this stuff trivial. Expect is also useful for testing these same applications. And by adding Tk, you can also wrap interactive applications in X11 GUIs.

Expect can make easy all sorts of tasks that are prohibitively difficult with anything else. You will find that Expect is an absolutely invaluable tool - using it, you will be able to automate tasks that you've never even thought of before - and you'll be able to do this automation quickly and easily.

Sounds good to me!

Tom Leys
Thanks. One of the first answers to this question (since deleted, apparently) suggested that I use twisted.*something*.FTP. I looked at it and it's not actually a very good fit I don't think, primarily because we need to block on every get or put. Also, it doesn't actually do much abstracting if you're not doing the kinds of things that it is specialized for.
quodlibetor