def request_file(self, file_requested = None): file_size = self.proxy.getFileSize(file_requested) print ('File size: ' + str(file_size) + ' Bytes') file_download = open(file_requested, 'w') timer = Timer() # 1.5 MB = 137 sec (1 KB) # 1.5 MB = 16 sec (10 KB) # 1.5 MB = 4 sec (50 KB) # 1.5 MB = 2.84 sec (100 KB) # 1.5 MB = 2.67 sec (150 KB) # 1.5 MB = 2.26 sec (500 KB) # 700 MB = 961 sec (16 min) (150 kb) 747 KB/s for size in range(0, file_size, self.DEFAULT_CHUNK_FILE_SIZE): # Loop each chunk size KB #print 'Requesting size: ' + str(size) async_result = self.proxy.begin_getFileChunk(file_requested, size, self.DEFAULT_CHUNK_FILE_SIZE) # Chunks #print 'Async call processed (' + str(size) + ')' try: data = self.proxy.end_getFileChunk(async_result) # Ice::MemoryLimitException or timeout except Ice.CommunicatorDestroyedException as e: #@UndefinedVariable ::Ice::CommunicatorDestroyedException sys.stderr.write('Error: The connection to comunicator was destroyed.\nClient abort.\n') return -1 except Exception as e: sys.stderr.write('Error: unknown exception in request_file %s\nClient abort.\n' % str(e)) #print 'Message:' + e.message #print 'Error:' + str(e.unknown) #print 'ice_name:' + str(e.ice_name()) #print 'String:' + e.__str__() return -1 speed = size / timer.duration_in_seconds() if size / 1024.0 < 1024: size = str(round(size / 1024.0, 2)) + ' KB' elif size / (1024.0 * 1024.0) < 1024: size = str(round(size / (1024.0 * 1024.0), 2)) + ' MB' elif size / float(1024.0 * 1024.0 * 1024.0) < 1024: size = str(round(size / (1024.0 * 1024.0 * 1024.0), 2)) + ' GB' file_download.write(data) if speed / 1024.0 < 1024: speed = str(round(speed / 1024.0, 2)) + ' KB/s' elif speed / (1024.0 * 1024.0) < 1024: speed = str(round(speed / (1024.0 * 1024.0), 2)) + ' MB/s' elif speed / (1024.0 * 1024.0 * 1024.0) < 1024: speed = str(round(speed / (1024.0 * 1024.0 * 1024.0), 2)) + ' GB/s' print ('Received (' + str(size) + ') ' + 'Speed: ' + str(speed)) file_download.close() print ('Data saved in ' + str(timer.duration_in_seconds()) + ' seconds')