Example—rz And sz Over rlogin
rz and sz are popular programs that perform XMODEM, YMODEM, and ZMODEM transfers with the controlling terminal. sz sends a file to the controlling terminal and rz reads a file from the controlling terminal. Used together, they can transfer files between two hosts. The following script uses rz and sz to transfer a file across a connection created by rlogin. This is handy if security restrictions do not permit the use of rcp.
spawn rlogin $host; set rz $spawn_id
expect "% "
send "stty -echo\r"
expect "% "
send "rz -v\r"
spawn sz $file
interact -u $rz "\r~" {
send -i $rz "\r~~"
}After starting rlogin, the script turns off echoing. This prevents the rz command itself from being echoed by the shell and simplifies starting sz. rz is started with the -v flag which inhibits printing of the message "rz ready. Type "sz file ..." to your modem program“. Once rz is ready, sz is started and the two are connected together using "interact -u“.
By default, rlogin provides an almost seamless connection. Unfortunately, there is no way to disable its escape character. The script works around this by watching for the character. The default escape is "~" but it is only detected by rlogin after a "\r“. The script watches for this sequence and sends an extra "~" to force rz to receive both the "\r" and "~“.
Most communication programs, rlogin included, provide an 8-bit connection. Alas, not all communication programs are so clean. Some implementations of telnet, for instance, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access