From: Bradford R. <bt...@po...> - 2007-03-16 04:06:41
|
Bryan, Looking at your code more closely, have you tried replacing qr/$_sftp_prompt/ with a literal string like qr/myprompt%/ or 'myprompt' ? Might be worth a try since the other two expect lines seem to be succeeding for you. Also, not that it matters, but I noticed that in sub that handles the password, you define $exp_self to hold the expect object instance, but then call $self->verbose(). Wasn't this giving you errors? On 3/15/07, Bryan Cox <co...@od...> wrote: > > Thanks, Austin! > > I copied your script verbatim, and it works. > However, it doesn't make any difference whether I include the space > after the prompt or not. It works in either case. > ( Well, the space is included in $sftp->before(), but that's beside the > point. ) > > So now I'll start turning your script into mine incrementally until it > breaks. > > I'll let you know what I discover. > > Bryan > > -----Original Message----- > From: Austin Schutz [mailto:te...@of...] > Sent: Thursday, March 15, 2007 2:40 PM > To: Bryan Cox > Cc: Bradford Ritchie; exp...@li... > Subject: Re: [Expectperl-discuss] Expect.pm & sftp > > On Wed, Mar 14, 2007 at 02:27:17PM -0700, Bryan Cox wrote: > > Here's an update: > > > > I've tried sftp, ftp, and rlogin. All fail in the same way: > > > > -> spawn id(4): Does `' > > -> match: > > -> pattern #1: -re `(?-xism:ame.*:)'? No. > > -> pattern #2: -re `(?-xism:assword:)'? No. > > -> pattern #3: -re `(?-xism:ftp>)'? No. > > -> pattern #4: -re `(?-xism:(\n)|(\r))'? No. > > -> Waiting for new data (10 seconds)... > > -> TIMEOUT > > > > This may be failing because of a race condition. You are not > waiting for a space after 'sftp>'. > I have a simple script I was able to use to get a listing of > files from sftp, so I don't think sftp itself is doing anything odd: > > #!/usr/bin/perl > use Expect; > > # usage: test.pl <[username@]host> <password> > > $sftp = Expect->spawn('sftp ' . $ARGV[0]); $sftp->exp_internal(1); > $sftp->expect(10, 'ord: '); print $sftp $ARGV[1]."\r"; $sftp->expect(10, > 'sftp> '); print $sftp "ls\r"; $sftp->expect(10, 'sftp> '); print > "Files:" . $sftp->before(); > > It's important to make sure you have received all the output > from the remote host before sending it anything. It may flush its > buffers before reading, thereby dumping whatever you thought you sent > it. > > Austin > |