Hi All,

I made a python ftp client on Windows XP which does binary get & put.

The issue here is that when I do FTP manually the time taken to either GET or PUT is about half the time taken by my ftp client.

Following is a snippet of my code; Is there a better approach to do this?

def get(self,filename):
        try:
            start = time.clock() 
            self.ftph.retrbinary('RETR '+ filename, open(filename, 'wb').write)
            end = time.clock() 
        except Exception:
            print "Error in downloading the remote file."
            return
        else:
            print "Successful download!"
            print "GET completed in %f seconds." % (end-start)
            return

Thanks

Recommended Answers

All 3 Replies

I'm not positive about this but I would assume that some of the time is consumed in the buffering of the file write process.

Perhaps in stead of an open file handle you could try an IOString, which after the operation is complete you could write to file in one chunk?

Hi Jim,

I was looking around for IOString module. But I could'nt find it, import IOString fails on windows.

Thanks

Lo siento mi amigo, it's StringIO... sometimes I type faster than my brain can process words. :\

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.