By Alvin Alexander. Last updated: June 4, 2016
I'm not going to explain this very much, but here's an Expect script that I wrote to test an FTP server:
#!/usr/bin/expect -f set verbose_flag 1 set username "al" set password "password" set host "localhost" set files {abc.pdf foo1.jpg foo2.jpg xyz.pdf} #log_user 0 set timeout -1 send_user "starting ncftp ..." spawn ncftp -u $username -p $password $host expect "ncftp*>" send_user "doing confirm/close ..." send "set confirm-close no\r" expect "ncftp*>" foreach f $files { send_user "putting $f ..." send "put $f\r" expect "ncftp*>" send_user "deleting $f ..." send "del $f\r" expect "ncftp*>" } send_user "saying goodbye ..." send "bye\r"
The script uses ncftp
to connect to the FTP server, but the thing I really like is that I just learned how to echo debug information to me, the user, with the send_user
command.
Other than that, the foreach
statement and the use of the list is all straight Tcl.