'Downloads a file from the remote server.
The file is cached in /tmp/pwntools-ssh-cache using a hash of the file, so
calling the function twice has little overhead.
Arguments:
remote(str): The remote filename to download
local(str): The local filename to save it to. Default is to infer it from the remote filename.'

def download_file(self, remote, local=None):

    if (not local):
        local = os.path.basename(os.path.normpath(remote))
    if (os.path.basename(remote) == remote):
        remote = os.path.join(self.cwd, remote)
    with self.progress(('Downloading    %r    to    %r' % (remote, local))) as p:
        local_tmp = self._download_to_cache(remote, p)
    if ((not os.path.exists(local)) or (hashes.sha256filehex(local_tmp) != hashes.sha256filehex(local))):
        shutil.copy2(local_tmp, local)
