code: def copy_dir(ftp, filename, outputdir, prefix, pattern=''):
    
    try:
      mode = ftp.stat(filename).st_mode
    except IOError, e:
      if e.errno == errno.ENOENT:
        logger.error("Log file " + filename + " does not exist")
        pass
    else:
      if mode & stat.S_IFREG:
        if re.match(pattern, filename) is not None:
          new_file = os.path.join(outputdir, "{0}-{1}".format(prefix, os.path.basename(filename)))
          ftp.get(filename, new_file)
      elif mode & stat.S_IFDIR:
        for f in ftp.listdir(filename):
          copy_dir(ftp, os.path.join(filename, f), outputdir,
                   "{0}_{1}".format(prefix, os.path.basename(filename)), pattern)
docs: Recursively copy a directory flattens the output into a single directory but
    prefixes the files with the path from the original input directory
    :param ftp:
    :param filename:
    :param outputdir:
    :param prefix:
    :param pattern: a regex pattern for files to match (by default matches everything)
    :return: