i get an error ‘Memory Error’ when it open and reads a file larger than 500mb.
if its less than 500mb it works perfectly..
im using the size for my progress bar’s maxvalue
self.ftp = FTP(hostname)
self.ftp.login(user, password)
self.f = open(self.filename,'rb')
with open(self.filename,'rb') as filein:
self.size = filein.read()
self.size = len(self.size)
Don’t use the
read()method since it reads the whole file into a string. You should use theos.stat()function to get the the file metadata, which returns a stat structure with the memberst_size. That’s the size in bytes of the file. You don’t have to read it all in first.For sending, also read in and write out in chunks (say 16kB), in a loop.