Python and Networking type questions

Hopefully this will not jump around and it will make sense.

  1. Does anyone know how many open concurrent FTP connections are allowed on one windows based PC?

  2. In Python/Jython when using the FTP, I can not seem to find the time out period. I would like to reduce it down from like 20 sec to like 5 or 10 but where is it?

  3. Lets say you use a commercial FTP client like CuteFTP or WSFTP. Why does it seem to transfer the data faster than say if you write script in Python/Jython?

for i in range(20): try: string = '10.0.0.'+str(i) k=i-10 filename = 'MACH_0'+str(k)+'.CSV' from ftplib import FTP ftp = FTP(string) ftp.login('david','bigbrother') print"Downloading :"+filename ftp.set_pasv(0) ftp.retrbinary('RETR ' + filename,open(filename,'wb').write) print"accept",i except: print"deny",i

Above is the code I have come up with so far and it seems to work well for some and not so good for others. The area I am having trouble with is in the file name. Locations 1 to 9 have a leading 0 (zero) while the other do not. How can I program in that if the number is less than or equal to 9 add the leading zero and if it is greater than 9 then just use the number?

Is there a way to say that while one file is downloading it will continue searching for another one an could keep tabs on how many so that the cap is not exceeded, that is if there is a cap.

Thanks one and all. Have a great weekend.

Ok, there was a lot in that post, I’ll try to provide the best answers I can, in order.

  1. There isn’t really a cap on the client machine, unless the FTP server imposes one. I mean, there is a cap (# of ephemeral ports available in Windows, typically 5000), but for all practical purposes, you won’t hit it.

  2. Sorry, I don’t know. The Python doc page for FTP doesn’t have any mention of a timeout, its probably using some OS default, but you might be able to set it somehow, not sure…

  3. I don’t know.

Leading Zero:

This is easy to do, just use string formatting, like so:

filename = 'MACH_%02d.CSV' % k

Multiple downloads at once:

You can do this using fpmi.system.invokeAsynchronous - here is an example:

[code]
for loopVar in range(20):
def doDownload(i=loopVar):
try:
string = ‘10.0.0.’+str(i)
k=i-10
filename = ‘MACH_0’+str(k)+’.CSV’
from ftplib import FTP
ftp = FTP(string)
ftp.login(‘david’,‘bigbrother’)
print"Downloading :"+filename
ftp.set_pasv(0)
ftp.retrbinary('RETR ’ + filename,open(filename,‘wb’).write)
print"accept",i
except:
print"deny",i

fpmi.system.invokeAsynchronous(doDownload)[/code]

Hope this helps,