Creating An External Command Set In Expect For SFTP?

I think I would approach this, by building a case on the end of your existing expect statement that can catch a pattern and parse it with a regexp. Then you just need a for loop to weed through the file and snag a match.

Up vote 2 down vote favorite share g+ share fb share tw.

Currently I have some code that is doing an SFTP via expect/tcl. Its something like this: send -i $ftpid "$cmd\r" expect { -i $ftpid -re "\n5\0-9\0-9 \^bB. *\nsftp> " { set errorCode 149 set errorInfo "SFTP command error on $cmd.

" return 1 } -i $ftpid "452 Err. *\nsftp> " { set errorCode 149 set errorInfo "SFTP 452 command error on $cmd. " return 1 } -i $ftpid "Invalid command*\nsftp> " { set errorCode 149 set errorInfo "SFTP invalid command on $cmd.

" return 1 } -i $ftpid -re "\n2\0-9\0-9 . *\nsftp> " { return 0 } } Occasionally I run into situations where an FTP server has return codes or messages that do not match what is already populated in the code base. Instead of modifying the core code for these what I would like to do is have an external file (ex: returncodes.

Tbl) where I can have a list of messages like: 552 Invalid Return*\nsftp>;; 400 Some Error*\nsftp>;; ... So then it will interpret it in the expect code like: -i $ftpid "552 Invalid Return*\nsftp>" { set errorCode set errorInfo "" return 1 } -i $ftpid "400 Some Error*\nsftp>" { set errorCode set errorInfo "" return 1 } I know how to read the external file and chop the variables up (open/read/split). However I cannot figure out how to create the loop needed within the expect statement. Was hoping someone might have an idea on how to accomplish this.

Tcl sftp expect link|improve this question asked Nov 9 '11 at 13:53ChuckMac254.

1 for a well-asked question. If only my heart didn't sink every time I see FTP (or SFTP) automation; I keep thinking “there's got to be a better way”. Not your fault though, just the inevitable result of the way that just slightly too much information is lost, again and again… – Donal Fellows Nov 10 '11 at 9:44.

I think I would approach this, by building a case on the end of your existing expect statement that can catch a pattern and parse it with a regexp. Then you just need a for loop to weed through the file and snag a match. You may need to play with the regexp to get it to work just right - sending \r a second time will align the expect buffer so that you can catch the error code.

(I don't know how you loaded the file, so right now I'm assuming it's a flat list split by "\n" and ";") expect { #your existing expect code here -i $ftpid -re "\0-9{3}. *\\*\nsftp>" { send -i $ftpid "\r" expect -i $ftpid "sftp>" regexp "^(.*\nsftp>)\nsftp>" $expect_out(buffer) garbage errorMsg set index 0 foreach element $filelistyouloaded { if { $element == $errorMsg } { set errorCode $filelistyouloaded(expr $index + 1) set errorInfo $filelistyouloaded(expr $index + 2) return 1 } incr index } } }.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions