#!/usr/bin/expect

set timeout 100
spawn
telnet xxx.xx.x.xx
expect “Username: ”
send “aaaar”
expect “Password: ”
send “bbbbr”
expect “*#”
send “conf tr”
expect “*#”
send “ip ftp username ftpuserr”
expect “*#”
send “ip ftp password ftppassr”
expect “*#”
send “exitr”
expect “*#”
send “copy ftp: disk0:r”
expect “*? ”
send “yyy.yy.yy.yr”
expect “*? ”
send “a.jpgr”
expect “*? ”
send “a.jpgr”
expect “*]”
send “r”
expect “*]”
send “r”
expect “*#”
send “exit”
exit

Save script and setup executable permission on it :
$ chmod +x router.exp

!
!

e.g :

eval spawn “telnet $ip”
expect “^Login:”

send “$usernamen”
expect “Password:”
send “$passwordn”
expect “prompt> ”
send “configure terminaln”
expect “prompt> ”
send “interface fa0/0n”