you can use a file for input by using redirection, I believe.
something like
telnet < ftpcommands.txt
in your case "ftpcommands.txt" or whatever you chose to name the file will need to contain the "code sequence" you gave, sans the "telnet" line at the top.