def METHOD_NAME(
    state: "State",
    host: "Host",
    filename_or_io,
    remote_filename,
    remote_temp_filename=None,  # ignored
    print_output: bool = False,
    print_input: bool = False,
    **command_kwargs,
):
    """
    Upload a local file or IO object by copying it to a temporary directory
    and then writing it to the upload location.
    """
    _, temp_filename = mkstemp()
    try:
        # Load our file or IO object and write it to the temporary file
        with get_file_io(filename_or_io) as file_io:
            with open(temp_filename, "wb") as temp_f:
                data = file_io.read()
                if isinstance(data, str):
                    data = data.encode()
                temp_f.write(data)
        # Copy the file using `cp` such that we support sudo/su
        status, _, stderr = run_shell_command(
            state,
            host,
            StringCommand("cp", temp_filename, QuoteString(remote_filename)),
            print_output=print_output,
            print_input=print_input,
            **command_kwargs,
        )
        if not status:
            raise IOError("\n".join(stderr))
    finally:
        os.remove(temp_filename)
    if print_output:
        click.echo(
            "{0}file copied: {1}".format(host.print_prefix, remote_filename),
            err=True,
        )
    return status