This looks like a classic xyproblem;
If your goal is to run scripts that do not exist on remote machines: there are better ways to achieve it without having to copy paste the entire script on to the remote machine's terminal.
For example: You can execute a local script on a remote machine through ssh:
cat script.sh | ssh me@myserver /bin/bash
Edit: thanksThanks for taking the time to edit in additional information to your question so that it would no longer be an xy question :) Cheersxyproblem Cheers!