From: Austin S. <te...@of...> - 2007-03-15 21:42:24
|
On Fri, Mar 16, 2007 at 03:18:31AM +0800, Aiman Hakimie wrote: > Hi, > > I'm new to this Expect. Just found out and decided to use in my current > project assignment. Really appreciate any help. I've trying to look > somewhere else (unsuccessfully) before decided to post it here. > > I want to use expect to do sftp. After login, I'll get the list of available > files in the directory, and from the list, I'll need to do some matching > with localhost list to get the file that is not in the local host. > > I trying to do something like this: > ....... > ........ > my $ret = $exp->expect(30,"sftp>") || die "Timeout waiting for sftp.\n"; > $exp->send("cd /tmp\n"); > > $exp->expect(10,"sftp>"); > my @file=$exp->send("ls A*\n"); > > foreach $file (@file) { > #do comparison > # if not match, > $exp->send("get $file\n"); > } > ..... > .... > > > Line "my @file=$exp->send("ls A*\n");" does;t give me the file list that I > want. I can do like this using Net::FTP, but not using Expect. > > Is there any way to achieve this? sftp (on my machine) uses the prompt 'sftp> '. That space is important. Typically you want to send \r instead of \n, that may or may not matter here. Use $exp->exp_internal(1) so you can watch what is sent/received. $exp->before() contains output before the last expect() match. in this case it will have the output of ls. Austin |