#!/bin/sh
# \
exec 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 60
spawn ftp $site
expect "*Name*:*"
send "anonymous\r"
expect "*Password:*"
send "$password\r"
expect "*ftp>*"
send "binary\r"
expect "*ftp>*"
send "cd $dir\r"
expect "*550*ftp>*" {exit 1} "*250*ftp>*"
send "get $theirname $myname\r"
expect "*550*ftp>*" {exit 1} "*200*226*ftp>*"
close
wait
send_user "FTP transfer ok\n"
exit 0
