I need to download many files from a single folder in a single server and so I'm looking for a way to do it quicker. After a little bit of reading it seems that either a multi-threading or asynchronous approach would work, but I can't seem to get either approach to work.
The async approach I'm using is below. This works, i.e. no errors, but it only downloads one file at a time, and so doesn't improve speed. Is there away to modify it so that I do improve speed?
async def get_file(self):
async with aioftp.ClientSession(self.host, self.port, self.login, self.password) as client:
async for path, info in client.list(recursive=True):
if info["type"] == "file":
await client.download(path, destination=self.dest_dir,write_into=True, block_size=self.block_size)
def async_update(self):
loop = asyncio.get_event_loop()
loop.run_until_complete(self.get_file())
loop.close()
Then I tried using the simple Pool() func in multiprocessing as below:
def simple_fetch(self,file)
file = open(self.dest_dir+filename, 'wb')
ftp.retrbinary('RETR ' + filename, file.write, 8192*(2^3)) #, 8192)
file.close()
def multi_fetch(self):
pool = Pool()
pool.map(self.simple_fetch,self.update_files)
pool.close()
pool.join()
But this fails with an error. I'll update with that error as soon as I'm back at the server.