spawn starts a process and connects to its standard input and output
expect waits for a string to appear in the standard output of the process
send sends a string to the standard input of the process

Example script responding on a netcat connection

#!/usr/bin/expect
set timeout -1
spawn nc -l 1234

while {1} {
	expect "hello"
	send "haliho\r"
}
   

Another example: mirroring local website on the web. Login information is in .netrc

#!/usr/bin/expect

system "logger 'starting http mirror'"
cd /var/www/html
spawn ftp ftp.fortunecity.com
expect "ftp>"
send "prompt\r"
expect "ftp>"
send "mput *.html\r"
expect "ftp>"
send "quit\r"