'Recursively downloads a directory from the remote server
Arguments:
local: Local directory
remote: Remote directory'

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

    remote = (remote or self.cwd)
    if self.sftp:
        remote = str(self.sftp.normalize(remote))
    else:
        with context.local(log_level='error'):
            remote = self.system(('readlink    -f    ' + sh_string(remote)))
    dirname = os.path.dirname(remote)
    basename = os.path.basename(remote)
    local = (local or '.')
    local = os.path.expanduser(local)
    self.info(('Downloading    %r    to    %r' % (basename, local)))
    with context.local(log_level='error'):
        remote_tar = self.mktemp()
        cmd = ('tar    -C    %s    -czf    %s    %s' % (sh_string(dirname), sh_string(remote_tar), sh_string(basename)))
        tar = self.system(cmd)
        if (0 != tar.wait()):
            self.error('Could    not    create    remote    tar')
        local_tar = tempfile.NamedTemporaryFile(suffix='.tar.gz')
        self.download_file(remote_tar, local_tar.name)
        tar = tarfile.open(local_tar.name)
        tar.extractall(local)
