urllib2 FTP Weirdness

Cameron Simpson cs at zip.com.au
Thu Feb 7 00:06:32 CET 2013


On 24Jan2013 04:12, Steven D'Aprano <steve+comp.lang.python at pearwood.info> wrote:
| On Thu, 24 Jan 2013 01:45:31 +0100, Hans Mulder wrote:
| > On 24/01/13 00:58:04, Chris Angelico wrote:
| >> Possibly it's some kind of race condition??
| > 
| > If urllib2 is using active mode FTP, then a firewall on your box could
| > explain what you're seeing.  But then, that's why active mode is hardly
| > used these days.
| 
| Explain please?

You do know the difference between active and passive FTP, yes?

| I cannot see how the firewall could possible distinguish between using a 
| temporary variable or not in these two snippets:
| 
| # no temporary variable hangs, or fails
| urllib2.urlopen("ftp://ftp2.census.gov/").read()
| 
| # temporary variable succeeds
| response = urllib2.urlopen("ftp://ftp2.census.gov/")
| response.read()

Timing. (Let me say I consider this scenario unlikely, very unlikely.
But...)

If the latter is consistently slightly slower then the firewall may be an
issue if active FTP is being used. "Active" FTP requires the FTP server
to connect to you to deliver the data: your end opens a listening TCP
socket and says "get", supplying the socket details.

Really the TCP protocol is suppose to be plenty robust enough for this
not to be timing - the opening SYN packet will get resent if the first
try doesn't elicit a response.

For this to work over a firewall the firewall must (1) read your FTP
control connection to see the port announcements and then (2) open a
firewall hole to let the FTP server connect in, probably including a
NAT or RDR arrangement to catch the incoming connection and deliver it
to your end. Let us not even consider other NATting firewalls further
upstream with your ISP.

Active FTP (the original FTP mode) is horrible. Passive FTP is more
conventional: the server listens and you connect to fetch the file. But
it still requires the server to accept connections on multiple ports;
ugh.

I hate FTP and really don't understand why it is still in common use.
-- 
Cameron Simpson <cs at zip.com.au>

To be positive: To be mistaken at the top of one's voice.
Ambrose Bierce (1842-1914), U.S. author. The Devil's Dictionary (1881-1906).



More information about the Python-list mailing list