EOF

Anjanesh Lekshminarayanan mail at anjanesh.net
Fri Aug 22 12:48:37 EDT 2008


|Hi

Im trying to download a file from a server. But how do I detect EOF ?
||


import urllib2

f1 = urllib2.urlopen('ftp://username:password@ftp.ftp-server.tld/data.zip')
f2 = file("data.zip", "wb")

while f1: # When to stop ?
      f2.write(f1.read(1024))

f1.close()
f2.close()

||

I can get the size & use it in a for loop :

||||length = float(f1.info().getheader("Content-Length"))
block = 1024

for i in range(0, int(length/block + 1)):
    s = f1.read(block)
    f2.write(s)|||


But this will not work for a file whose size is not known. So I need to 
get this done via EOF method.

Thanks



More information about the Python-list mailing list