code: def transfer_file(context, in_path, out_path, sync=False, set_owner=False):
      
      out_path = os.path.abspath(out_path)
      fd, tmp_path = tempfile.mkstemp(suffix='.tmp',
                                      prefix='.ansible_mitogen_transfer-',
                                      dir=os.path.dirname(out_path))
      fp = os.fdopen(fd, 'wb', mitogen.core.CHUNK_SIZE)
      LOG.debug('transfer_file(%r) temporary file: %s', out_path, tmp_path)
  
      try:
          try:
              ok, metadata = mitogen.service.FileService.get(
                  context=context,
                  path=in_path,
                  out_fp=fp,
              )
              if not ok:
                  raise IOError('transfer of %r was interrupted.' % (in_path,))
  
              set_file_mode(tmp_path, metadata['mode'], fd=fp.fileno())
              if set_owner:
                  set_file_owner(tmp_path, metadata['owner'], metadata['group'],
                                 fd=fp.fileno())
          finally:
              fp.close()
  
          if sync:
              os.fsync(fp.fileno())
          os.rename(tmp_path, out_path)
      except BaseException:
          os.unlink(tmp_path)
          raise
  
      os.utime(out_path, (metadata['atime'], metadata['mtime']))
docs: Streamily download a file from the connection multiplexer process in the
      controller.
  
      :param mitogen.core.Context context:
          Reference to the context hosting the FileService that will transmit the
          file.
      :param bytes in_path:
          FileService registered name of the input file.
      :param bytes out_path:
          Name of the output path on the local disk.
      :param bool sync:
          If :data:`True`, ensure the file content and metadat are fully on disk
          before renaming the temporary file over the existing file. This should
          ensure in the case of system crash, either the entire old or new file
          are visible post-reboot.
      :param bool set_owner:
          If :data:`True`, look up the metadata username and group on the local
          system and file the file owner using :func:`os.fchmod`.