When you can’t pipe an input file to automate a process, especially when you need to enter a password such as ftp-ing to some server e.g.:
ftp user@ftp.myhost.com < myFTPCommands.txt
The above fails when ftp asks for a password. This is where expect comes to the rescue! e.g.:
#myExpectFile.exp #Disable's expect's default 10 seconds timeout set timeout -1 spawn ftp user@ftp.myhost.com expect "password:" send "mySoSecuredPassword\r" expect "ftp>" send "get someFileFromFTP.txt\r" expect "ftp>" send "put someFileFromLocalhost.txt\r" expect "ftp>" send "quit\r"
Save the file and then try running it:
expect myExpectFile.exp
Magic happens!