You are going to have a very hard time unless the strings that are sent/received are always constant. If it is a completely static format kind of give and take (like FTP, <suppress verbose>, cd <dir>, mget *, exit would be) , then autoexpect.
autoexpect
do all the commands, example, telnet, ssh, ftp, etc
exit
script created called script.exp. It will do, and EXPECT everything you just did.
RO
man autoexpect
and google on autoexpect
|