Since this is all going over an unencrypted network session, you should be able to use a packet sniffer (like tcpdump or the GUI sniffer formerly known as Ethereal) to see exactly what is being sent. That should tell you definitively whether your script is sending the right thing or not.
Sometimes when sequences are meant to be sent by hand, they require a short pause before, after, or between the characters being sent (for example, many modems will do this with +++ to stop outgoing IP packets from sending a modem escape).