#!/usr/bin/expect -f set timeout 5 spawn lftp -e {set cmd:fail-exit yes} expect "lftp :~> " send -- "help ls\r" expect "lftp :~> " send -- "help cls\r" expect { "lftp :~> " { exit 0 } eof { exit 1 } }