def execute_remote_ssh(self, *, connect_to={}, root, run_script=True):
        """
        Execute build plan using the remote SSH strategy. Files from the build
        plan are transferred via SFTP to the directory ``root`` on a  remote
        server. If ``run_script`` is ``True``, the ``paramiko`` SSH client will
        then run ``{script}.sh``. ``root`` can either be an absolute or
        relative (to the login directory) path.

        ``connect_to`` is a dictionary that holds all input arguments to
        ``paramiko``'s ``SSHClient.connect``
        (`documentation <https://docs.paramiko.org/en/latest/api/client.html#paramiko.client.SSHClient.connect>`_).
        At a minimum, the ``hostname`` input argument must be supplied in this
        dictionary as the remote server.

        Returns :class:`RemoteSSHBuildProducts`.
        """
        from paramiko import SSHClient

        with SSHClient() as client:
            client.load_system_host_keys()
            client.connect(**connect_to)

            with client.open_sftp() as sftp:
                def mkdir_exist_ok(path):
                    try:
                        sftp.mkdir(str(path))
                    except OSError as e:
                        # mkdir fails if directory exists. This is fine in amaranth.build.
                        # Reraise errors containing e.errno info.
                        if e.errno:
                            raise e

                def mkdirs(path):
                    # Iteratively create parent directories of a file by iterating over all
                    # parents except for the root ("."). Slicing the parents results in
                    # TypeError, so skip over the root ("."); this also handles files
                    # already in the root directory.
                    for parent in reversed(path.parents):
                        if parent == pathlib.PurePosixPath("."):
                            continue
                        else:
                            mkdir_exist_ok(parent)

                mkdir_exist_ok(root)

                sftp.chdir(root)
                for filename, content in self.files.items():
                    filename = pathlib.PurePosixPath(filename)
                    assert ".." not in filename.parts

                    mkdirs(filename)

                    mode = "t" if isinstance(content, str) else "b"
                    with sftp.file(str(filename), "w" + mode) as f:
                        f.set_pipelined()
                        # "b/t" modifier ignored in SFTP.
                        if mode == "t":
                            f.write(content.encode("utf-8"))
                        else:
                            f.write(content)

            if run_script:
                transport = client.get_transport()
                channel = transport.open_session()
                channel.set_combine_stderr(True)

                cmd = (f"if [ -f ~/.profile ]; then . ~/.profile; fi && "
                       f"cd {root} && exec $0 {self.script}.sh")
                channel.exec_command(f"sh -c '{cmd}'")

                # Show the output from the server while products are built.
                buf = channel.recv(1024)
                while buf:
                    print(buf.decode("utf-8", errors="replace"), end="")
                    buf = channel.recv(1024)

        return RemoteSSHBuildProducts(connect_to, root)

        Execute build plan using the remote SSH strategy. Files from the build
        plan are transferred via SFTP to the directory ``root`` on a  remote
        server. If ``run_script`` is ``True``, the ``paramiko`` SSH client will
        then run ``{script}.sh``. ``root`` can either be an absolute or
        relative (to the login directory) path.

        ``connect_to`` is a dictionary that holds all input arguments to
        ``paramiko``'s ``SSHClient.connect``
        (`documentation <https://docs.paramiko.org/en/latest/api/client.html#paramiko.client.SSHClient.connect>`_).
        At a minimum, the ``hostname`` input argument must be supplied in this
        dictionary as the remote server.

        Returns :class:`RemoteSSHBuildProducts`.
        
amaranth/build/run.py