FTP自动登录脚本
这个是简洁脚本:
1 2 3 4 5 6 7 8 9 10 11 | #!/usr/bin/expect -f spawn ftp ftp.forzw.com expect "Password: " send -- "passwd\r" expect "ftp.forzw.com\r\r" Last login: Sun Apr 1 21:32:36 2012 from localhost.localdomain\r\r ]0; " send -- "cd /pub/test\r" expect "\r /pub/test\r" send -- "get program.test\r" expect "File transfered" send -- "exit\r" |
复杂的脚本:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | #!/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" |