#!expect -f

set site [lindex $argv 0]
set dir [lindex $argv 1]
set theirname [lindex $argv 2]
set myname [lindex $argv 3]
set password "$env(USER)@"

set timeout 30
spawn ftp $site
expect "*Name*:*" {set nop 0} \
	timeout {exit 10}
send "anonymous\r"
expect "*Password:*" {set nop 0} \
	timeout {exit 20}
send "$password\r"
expect "*ftp>*" {set nop 0} \
	timeout {exit 30}
send "binary\r"
expect "*ftp>*" {set nop 0} \
	timeout {exit 40}
send "cd $dir\r"
expect "*550*ftp>*" {exit 1}  \
	"*250*ftp>*" {set nop 0} \
	timeout	{exit 50}
send "get $theirname $myname\r"
expect "*550*ftp>*" {exit 1}  \
	"*200*226*ftp>*" {set nop 0} \
	timeout	{exit 60}
close
wait
send_user "FTP transfer ok\n"
exit 0
