From: Bryan C. <co...@od...> - 2007-03-13 20:08:14
|
So, I've combed the archives and found similar problems, but no solution (usually pty settings) that works for me. =20 I can't install Net::SFTP, so I'm trying to implement an automated sftp via Expect. The example below uses a password login, but the problem is exactly the same if I=20 use publickey authorization. =20 # Spawn the sftp process if ( not $expect->spawn( $_sftp_program, @cmd_parameters ) ) { carp "ERROR: Unable to spawn $_sftp_program : $OS_ERROR\n"; } else { $expect->restart_timeout_upon_receive(1); # Wait for prompt, send password if necessary my @expect_result =3D $expect->expect( $_expect_timeout, [ '-re', qr/password:/ =3D> sub { my $exp_self =3D shift; print "\n\n-- sftp password prompt detected.\n" if ( ( $self->verbose() > 1 ) or $self->debug_ftp() ); $exp_self->send( $self->password() . "\n" ); print "-- sftp password sent\n\n" if ( ( $self->verbose() > 1 ) or $self->debug_ftp() ); exp_continue() ; } ], [ '-re', qr/$_sftp_prompt/ ], # [ '-re', qr/(\n)|(\r)/ ] ); The process spawns ok, and the password prompt is detected. The send() works, and the log shows that the password is accepted. After that, expect sees nothing except a line return. If I expect() on that (commented out above), I can then issue a send( "ls\n" ). Again, expect() sees nothing,=20 but I can see the results and the prompt delivered to my terminal, usually AFTER the timeout (depending on pty settings). =20 In the log, the last line before timeout is generally around =20 debug1: Authentication succeeded (password).^M debug2: fd 4 setting O_NONBLOCK^M debug3: fd 5 is O_NONBLOCK^M debug2: fd 6 setting O_NONBLOCK^M debug1: channel 0: new [client-session]^M debug3: ssh_session2_open: channel_new: 0^M debug2: channel 0: send open^M debug1: Entering interactive session.^M On screen, I see =20 -> -- sftp password sent -> Continuing expect, restarting timeout... -> spawn id(4): Does ` ' -> match: -> pattern #1: -re `(?-xism:password:)'? No. -> pattern #2: -re `(?-xism:sftp>)'? No. -> pattern #3: -re `(?-xism:(\n)|(\r))'? No. -> Waiting for new data (10 seconds)... -> spawn id(4): new data. -> spawn id(4): read 2 byte(s). -> spawn id(4): Does ` \r\n' -> match: -> pattern #1: -re `(?-xism:password:)'? No. -> pattern #2: -re `(?-xism:sftp>)'? No. -> pattern #3: -re `(?-xism:(\n)|(\r))'? YES!! -> Before match string: ` ' -> Match string: `\r' -> After match string: `\n' -> Matchlist: (`', `\r') -> Returning from expect successfully. -> spawn id(4): accumulator: `\n' Retrieving a list of remote files ... -> Sending 'ls\n' to spawn id(4) -> at /home/coxb/lib/Expect.pm line 1277 -> Expect::print('Expect=3DGLOB(0x30a2ca94)', 'ls\x{a}') called at /home/coxb/lib/ODS/FtpSftp.pm line 396 -> = ODS::FtpSftp::_list_files_sftp('ODS::FtpSftp=3DHASH(0x30a2b588)') called at /home/coxb/lib/ODS/FtpSftp.pm line 96 -> ODS::FtpSftp::list_files('ODS::FtpSftp=3DHASH(0x30a2b588)') = called at ./file_xfer line 253 -> expect(Expect=3DGLOB(0x30a2ca94) 10 ARRAY(0x30a2f2ec)) called... -> expect(): handling param 'ARRAY(0x30a2f2ec)'... -> Starting EXPECT pattern matching... -> at /home/coxb/lib/Expect.pm line 564 -> Expect::expect('Expect=3DGLOB(0x30a2ca94)', 10, 'ARRAY(0x30a2f2ec)') called at /home/coxb/lib/ODS/FtpSftp.pm line 397 -> = ODS::FtpSftp::_list_files_sftp('ODS::FtpSftp=3DHASH(0x30a2b588)') called at /home/coxb/lib/ODS/FtpSftp.pm line 96 -> ODS::FtpSftp::list_files('ODS::FtpSftp=3DHASH(0x30a2b588)') = called at ./file_xfer line 253 -> spawn id(4): beginning expect. -> Timeout: 10 seconds. -> Current time: Tue Mar 13 12:47:43 2007 -> spawn id(4): list of patterns: -> #1: -re `(?-xism:sftp>)' -> spawn id(4): Does `\n' -> match: -> pattern #1: -re `(?-xism:sftp>)'? No. -> Waiting for new data (10 seconds)... -> spawn id(4): new data. -> spawn id(4): read 4 byte(s). -> ls -> spawn id(4): Does `\nls\r\n' -> match: -> pattern #1: -re `(?-xism:sftp>)'? No. -> Waiting for new data (10 seconds)... -> sftp> THEFILEIMLOOKINGFOR.DAT -> sftp> TIMEOUT I've tried every stty setting for both control and slave, including -file. Nothing works. =20 I'm connecting from AIX 5.3 back to myself, so the machine is known. =20 I'd really appreciate some help on this. =20 Thanks, =20 -- Bryan =20 =20 |
From: Austin S. <te...@of...> - 2007-03-13 23:31:47
|
On Tue, Mar 13, 2007 at 01:07:50PM -0700, Bryan Cox wrote: > So, I've combed the archives and found similar problems, but no > solution (usually pty settings) that works for me. > > I can't install Net::SFTP, so I'm trying to implement an automated sftp > via Expect. > The example below uses a password login, but the problem is exactly the > same if I > use publickey authorization. > > > # Spawn the sftp process > if ( not $expect->spawn( $_sftp_program, @cmd_parameters ) ) { > carp "ERROR: Unable to spawn $_sftp_program : $OS_ERROR\n"; > } > else { > $expect->restart_timeout_upon_receive(1); > > # Wait for prompt, send password if necessary > my @expect_result = $expect->expect( $_expect_timeout, > [ '-re', qr/password:/ => > sub { my $exp_self = shift; > print "\n\n-- sftp password prompt detected.\n" > if ( ( $self->verbose() > 1 ) > or $self->debug_ftp() ); > $exp_self->send( $self->password() . "\n" ); ^^^^ Some programs require you to send an \r instead of an \n. That looks like it may be happening here. Austin |
From: Bryan C. <co...@od...> - 2007-03-14 15:40:38
|
Thanks for the suggestion, Austin, but that's not the case. No combination of \r and \n makes any difference. Actually, the application sees whatever I send(), and it responds appropriately. The problem is that expect() doesn't see the response. -- Bryan=20 -----Original Message----- From: Austin Schutz [mailto:te...@of...]=20 Sent: Tuesday, March 13, 2007 4:16 PM To: Bryan Cox Cc: exp...@li... Subject: Re: [Expectperl-discuss] Expect.pm & sftp On Tue, Mar 13, 2007 at 01:07:50PM -0700, Bryan Cox wrote: > So, I've combed the archives and found similar problems, but no=20 > solution (usually pty settings) that works for me. > =20 > I can't install Net::SFTP, so I'm trying to implement an automated=20 > sftp via Expect. > The example below uses a password login, but the problem is exactly=20 > the same if I use publickey authorization. > =20 >=20 > # Spawn the sftp process > if ( not $expect->spawn( $_sftp_program, @cmd_parameters ) ) { > carp "ERROR: Unable to spawn $_sftp_program : $OS_ERROR\n"; > } > else { > $expect->restart_timeout_upon_receive(1); >=20 > # Wait for prompt, send password if necessary > my @expect_result =3D $expect->expect( $_expect_timeout, > [ '-re', qr/password:/ =3D> > sub { my $exp_self =3D shift; > print "\n\n-- sftp password prompt detected.\n" > if ( ( $self->verbose() > 1 ) > or $self->debug_ftp() ); > $exp_self->send( $self->password() . "\n" ); ^^^^ Some programs require you to send an \r instead of an \n. That looks like it may be happening here. Austin |
From: Bradford R. <bri...@po...> - 2007-03-14 18:15:55
|
Have you tried connecting to other SFTP servers? At least try connecting to one that's truly remote. Perhaps the output is somehow being sent directly to your tty or through a different channel than, um, expected. I don't know much about the inner workings of pty's (or ssh either), but I do hear a lot of frustration from other people trying to automate on top of them. It seems there's a lot going on behind the scenes that makes things not quite as transparent as they might seem. I would definitely try "messing around" and try different things that logically should make no difference. You may discover something that way. Try running it on a different host. Spawn a program other than SFTP. Good luck. -- Brad On 3/13/07, Bryan Cox <co...@od...> wrote: > > So, I've combed the archives and found similar problems, but no solution > (usually pty settings) that works for me. > > I can't install Net::SFTP, so I'm trying to implement an automated sftp > via Expect. > The example below uses a password login, but the problem is exactly the > same if I > use publickey authorization. > > > # Spawn the sftp process > if ( not $expect->spawn( $_sftp_program, @cmd_parameters ) ) { > carp "ERROR: Unable to spawn $_sftp_program : $OS_ERROR\n"; > } > else { > $expect->restart_timeout_upon_receive(1); > > # Wait for prompt, send password if necessary > my @expect_result = $expect->expect( $_expect_timeout, > [ '-re', qr/password:/ => > sub { my $exp_self = shift; > print "\n\n-- sftp password prompt detected.\n" > if ( ( $self->verbose() > 1 ) > or $self->debug_ftp() ); > $exp_self->send( $self->password() . "\n" ); > print "-- sftp password sent\n\n" > if ( ( $self->verbose() > 1 ) > or $self->debug_ftp() ); > exp_continue() ; > } > ], > [ '-re', qr/$_sftp_prompt/ ], > # [ '-re', qr/(\n)|(\r)/ ] > ); > The process spawns ok, and the password prompt is detected. The send() > works, and > the log shows that the password is accepted. After that, expect sees > nothing except a line return. > If I expect() on that (commented out above), I can then issue a send( > "ls\n" ). Again, expect() sees nothing, > but I can see the results and the prompt delivered to my terminal, usually > AFTER the timeout (depending on pty settings). > > In the log, the last line before timeout is generally around > > debug1: Authentication succeeded (password).^M > debug2: fd 4 setting O_NONBLOCK^M > debug3: fd 5 is O_NONBLOCK^M > debug2: fd 6 setting O_NONBLOCK^M > debug1: channel 0: new [client-session]^M > debug3: ssh_session2_open: channel_new: 0^M > debug2: channel 0: send open^M > debug1: Entering interactive session.^M > On screen, I see > > -> -- sftp password sent > -> Continuing expect, restarting timeout... > -> spawn id(4): Does ` ' > -> match: > -> pattern #1: -re `(?-xism:password:)'? No. > -> pattern #2: -re `(?-xism:sftp>)'? No. > -> pattern #3: -re `(?-xism:(\n)|(\r))'? No. > -> Waiting for new data (10 seconds)... > -> spawn id(4): new data. > -> spawn id(4): read 2 byte(s). > -> spawn id(4): Does ` \r\n' > -> match: > -> pattern #1: -re `(?-xism:password:)'? No. > -> pattern #2: -re `(?-xism:sftp>)'? No. > -> pattern #3: -re `(?-xism:(\n)|(\r))'? YES!! > -> Before match string: ` ' > -> Match string: `\r' > -> After match string: `\n' > -> Matchlist: (`', `\r') > -> Returning from expect successfully. > -> spawn id(4): accumulator: `\n' > Retrieving a list of remote files .. > -> Sending 'ls\n' to spawn id(4) > -> at /home/coxb/lib/Expect.pm line 1277 > -> Expect::print('Expect=GLOB(0x30a2ca94)', 'ls\x{a}') called at > /home/coxb/lib/ODS/FtpSftp.pm line 396 > -> ODS::FtpSftp::_list_files_sftp('ODS::FtpSftp=HASH(0x30a2b588)') > called at /home/coxb/lib/ODS/FtpSftp.pm line 96 > -> ODS::FtpSftp::list_files('ODS::FtpSftp=HASH(0x30a2b588)') called > at /file_xfer line 253 > -> expect(Expect=GLOB(0x30a2ca94) 10 ARRAY(0x30a2f2ec)) called... > -> expect(): handling param 'ARRAY(0x30a2f2ec)'... > -> Starting EXPECT pattern matching... > -> at /home/coxb/lib/Expect.pm line 564 > -> Expect::expect('Expect=GLOB(0x30a2ca94)', 10, 'ARRAY(0x30a2f2ec)') > called at /home/coxb/lib/ODS/FtpSftp.pm line 397 > -> ODS::FtpSftp::_list_files_sftp('ODS::FtpSftp=HASH(0x30a2b588)') > called at /home/coxb/lib/ODS/FtpSftp.pm line 96 > -> ODS::FtpSftp::list_files('ODS::FtpSftp=HASH(0x30a2b588)') called > at /file_xfer line 253 > -> spawn id(4): beginning expect. > -> Timeout: 10 seconds. > -> Current time: Tue Mar 13 12:47:43 2007 > -> spawn id(4): list of patterns: > -> #1: -re `(?-xism:sftp>)' > -> spawn id(4): Does `\n' > -> match: > -> pattern #1: -re `(?-xism:sftp>)'? No. > -> Waiting for new data (10 seconds)... > -> spawn id(4): new data. > -> spawn id(4): read 4 byte(s). > -> ls > -> spawn id(4): Does `\nls\r\n' > -> match: > -> pattern #1: -re `(?-xism:sftp>)'? No. > -> Waiting for new data (10 seconds)... > *-> sftp> THEFILEIMLOOKINGFOR.DAT > -> sftp> TIMEOUT* > I've tried every stty setting for both control and slave, including > -file. Nothing works. > > I'm connecting from AIX 5.3 back to myself, so the machine is known. > > I'd really appreciate some help on this. > > Thanks, > > -- Bryan > > > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share > your > opinions on IT & business topics through brief surveys-and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > Expectperl-discuss mailing list > Exp...@li... > https://lists.sourceforge.net/lists/listinfo/expectperl-discuss > > |
From: Bradford R. <bt...@po...> - 2007-03-14 18:20:02
|
Bryan, Have you tried connecting to other SFTP servers? At least try connecting to one that's truly remote. Perhaps the output is somehow being sent directly to your tty or through a different channel than, um, expected. I don't know much about the inner workings of pty's (or ssh either), but I do hear a lot of frustration from other people trying to automate on top of them. It seems there's a lot going on behind the scenes that makes things not quite as transparent as they might seem. I would definitely try "messing around" and try different things that logically should make no difference. You may discover something that way. Try running it on a different host. Spawn a program other than SFTP. Good luck. -- Brad > |
From: Bryan C. <co...@od...> - 2007-03-14 21:27:58
|
Here's an update: =20 I've tried sftp, ftp, and rlogin. All fail in the same way: =20 -> 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 With sftp, I managed to see the ssh password prompt and send a password, but just as soon as any interaction with the remote machine starts, expect() fails to see anything from the remote machine. I see connection info and prompts passed to my terminal, though. =20 -- Bryan ________________________________ From: btr...@gm... [mailto:btr...@gm...] On Behalf Of Bradford Ritchie Sent: Wednesday, March 14, 2007 11:20 AM To: Bryan Cox Cc: exp...@li... Subject: Re: [Expectperl-discuss] Expect.pm & sftp Bryan, Have you tried connecting to other SFTP servers? At least try connecting to one that's truly remote. Perhaps the output is somehow being sent directly to your tty or through a different channel than, um, expected. I don't know much about the inner workings of pty's (or ssh either), but I do hear a lot of frustration from other people trying to automate on top of them. It seems there's a lot going on behind the scenes that makes things not quite as transparent as they might seem.=20 I would definitely try "messing around" and try different things that logically should make no difference. You may discover something that way. Try running it on a different host. Spawn a program other than SFTP.=20 Good luck. -- Brad |
From: Austin S. <te...@of...> - 2007-03-15 21:55:35
|
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 |
From: Bryan C. <co...@od...> - 2007-03-15 22:40:35
|
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=20 -----Original Message----- From: Austin Schutz [mailto:te...@of...]=20 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: > =20 > I've tried sftp, ftp, and rlogin. All fail in the same way: > =20 > -> 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 >=20 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 =3D 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 |
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 > |
From: Roland G. <rgi...@cp...> - 2007-03-19 15:36:31
|
hmm, first of all, why do you have to use sftp? how about using scp? :o) i wrote the example script below und tried it on cygwin, linux and aix. it works on both cygwin und aix, but has problems on linux, it doesn't capture the 'ls' output. so i guess there is something fishy with the pty on linux. the prompt correctly goes to Expects pty but the 'ls' output somehow manages to go directly to the terminal... :-( my $sftp = Expect->spawn("sftp $ARGV[0]"); my $sentLS; my $result; $sftp->expect(10, [ qr/sftp> \Z/ => sub { if ($sentLS) { $sftp->send("quit\r"); } else { $sftp->send("ls -1\r"); $sentLS = 1; } exp_continue; } ], [ qr/.+/ => sub { $result .= $sftp->match(); exp_continue; } ], [ timeout => sub { print "Timeout\n" } ], [ eof => sub { print "EOF\n" } ], ); $result =~ s{\r(?!\n)}{\n}g; $result =~ s{^}{>< }smg; print "$result\n"; On 3/13/07, Bryan Cox <co...@od...> wrote: > > > So, I've combed the archives and found similar problems, but no solution > (usually pty settings) that works for me. > > I can't install Net::SFTP, so I'm trying to implement an automated sftp via > Expect. > The example below uses a password login, but the problem is exactly the same > if I > use publickey authorization. > > > > # Spawn the sftp process > if ( not $expect->spawn( $_sftp_program, @cmd_parameters ) ) { > carp "ERROR: Unable to spawn $_sftp_program : $OS_ERROR\n"; > } > else { > $expect->restart_timeout_upon_receive(1); > > # Wait for prompt, send password if necessary > my @expect_result = $expect->expect( $_expect_timeout, > [ '-re', qr/password:/ => > sub { my $exp_self = shift; > print "\n\n-- sftp password prompt detected.\n" > if ( ( $self->verbose() > 1 ) > or $self->debug_ftp() ); > $exp_self->send( $self->password() . "\n" ); > print "-- sftp password sent\n\n" > if ( ( $self->verbose() > 1 ) > or $self->debug_ftp() ); > exp_continue() ; > } > ], > [ '-re', qr/$_sftp_prompt/ ], > # [ '-re', qr/(\n)|(\r)/ ] > ); > > The process spawns ok, and the password prompt is detected. The send() > works, and > the log shows that the password is accepted. After that, expect sees > nothing except a line return. > If I expect() on that (commented out above), I can then issue a send( "ls\n" > ). Again, expect() sees nothing, > but I can see the results and the prompt delivered to my terminal, usually > AFTER the timeout (depending on pty settings). > > In the log, the last line before timeout is generally around > > debug1: Authentication succeeded (password).^M > debug2: fd 4 setting O_NONBLOCK^M > debug3: fd 5 is O_NONBLOCK^M > debug2: fd 6 setting O_NONBLOCK^M > debug1: channel 0: new [client-session]^M > debug3: ssh_session2_open: channel_new: 0^M > debug2: channel 0: send open^M > debug1: Entering interactive session.^M > > On screen, I see > > -> -- sftp password sent > -> Continuing expect, restarting timeout... > -> spawn id(4): Does ` ' > -> match: > -> pattern #1: -re `(?-xism:password:)'? No. > -> pattern #2: -re `(?-xism:sftp>)'? No. > -> pattern #3: -re `(?-xism:(\n)|(\r))'? No. > -> Waiting for new data (10 seconds)... > -> spawn id(4): new data. > -> spawn id(4): read 2 byte(s). > -> spawn id(4): Does ` \r\n' > -> match: > -> pattern #1: -re `(?-xism:password:)'? No. > -> pattern #2: -re `(?-xism:sftp>)'? No. > -> pattern #3: -re `(?-xism:(\n)|(\r))'? YES!! > -> Before match string: ` ' > -> Match string: `\r' > -> After match string: `\n' > -> Matchlist: (`', `\r') > -> Returning from expect successfully. > -> spawn id(4): accumulator: `\n' > Retrieving a list of remote files .. > -> Sending 'ls\n' to spawn id(4) > -> at /home/coxb/lib/Expect.pm line 1277 > -> Expect::print('Expect=GLOB(0x30a2ca94)', 'ls\x{a}') > called at /home/coxb/lib/ODS/FtpSftp.pm line 396 > -> > ODS::FtpSftp::_list_files_sftp('ODS::FtpSftp=HASH(0x30a2b588)') > called at /home/coxb/lib/ODS/FtpSftp.pm line 96 > -> > ODS::FtpSftp::list_files('ODS::FtpSftp=HASH(0x30a2b588)') > called at /file_xfer line 253 > -> expect(Expect=GLOB(0x30a2ca94) 10 ARRAY(0x30a2f2ec)) called... > -> expect(): handling param 'ARRAY(0x30a2f2ec)'... > -> Starting EXPECT pattern matching... > -> at /home/coxb/lib/Expect.pm line 564 > -> Expect::expect('Expect=GLOB(0x30a2ca94)', 10, > 'ARRAY(0x30a2f2ec)') called at /home/coxb/lib/ODS/FtpSftp.pm line 397 > -> > ODS::FtpSftp::_list_files_sftp('ODS::FtpSftp=HASH(0x30a2b588)') > called at /home/coxb/lib/ODS/FtpSftp.pm line 96 > -> > ODS::FtpSftp::list_files('ODS::FtpSftp=HASH(0x30a2b588)') > called at /file_xfer line 253 > -> spawn id(4): beginning expect. > -> Timeout: 10 seconds. > -> Current time: Tue Mar 13 12:47:43 2007 > -> spawn id(4): list of patterns: > -> #1: -re `(?-xism:sftp>)' > -> spawn id(4): Does `\n' > -> match: > -> pattern #1: -re `(?-xism:sftp>)'? No. > -> Waiting for new data (10 seconds)... > -> spawn id(4): new data. > -> spawn id(4): read 4 byte(s). > -> ls > -> spawn id(4): Does `\nls\r\n' > -> match: > -> pattern #1: -re `(?-xism:sftp>)'? No. > -> Waiting for new data (10 seconds)... > -> sftp> THEFILEIMLOOKINGFOR.DAT > -> sftp> TIMEOUT > > I've tried every stty setting for both control and slave, including -file. > Nothing works. > > I'm connecting from AIX 5.3 back to myself, so the machine is known. > > I'd really appreciate some help on this. > > Thanks, > > -- Bryan > > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys-and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > Expectperl-discuss mailing list > Exp...@li... > https://lists.sourceforge.net/lists/listinfo/expectperl-discuss > > |
From: Roland G. <rgi...@cp...> - 2007-03-19 16:12:13
|
even Net::SFTP? which should be a pure-perl-implementation? On 3/19/07, Blackstone, J. David <jda...@ci...> wrote: > -----Original Message----- > From: exp...@li... > [mailto:exp...@li...] On Behalf Of > Roland Giersig > Sent: Monday, March 19, 2007 15:36 > To: Bryan Cox > Cc: exp...@li... > Subject: Re: [Expectperl-discuss] Expect.pm & sftp > > > hmm, first of all, why do you have to use sftp? how about using scp? > :o) > > I know that I personally have a pair of very unfortunate situations > where the vendor of a certain piece of equipment allows sftp but does > not allow scp. I have no idea how they even configure it to work that > way. > > It's awful because Perl's various sftp interface modules are somewhat > buggy. > > Jdb > |
From: Bryan C. <co...@od...> - 2007-03-20 18:43:33
|
Brad and Austin, =20 I've finally figured this thing out (sort of). Expect works fine in a "normal" environment. =20 We have a utility built in-house that we use to log the output of our scripts. That utility does some forking, redirection of stdin & stdout, and unbuffering before I make my Expect call. Between the two modules, there's just one too many redirects or something. I'm not sure if I'll ever get it sorted out to the point where I can make them work together, but they work fine independently. =20 I've appreciated your help, and hope I can return the favor some time. =20 Bryan ________________________________ From: btr...@gm... [mailto:btr...@gm...] On Behalf Of Bradford Ritchie Sent: Thursday, March 15, 2007 9:07 PM To: Bryan Cox Cc: exp...@li... Subject: Re: [Expectperl-discuss] Expect.pm & sftp 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. =20 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:=20 Thanks, Austin! =09 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=20 point. ) =09 So now I'll start turning your script into mine incrementally until it breaks. =09 I'll let you know what I discover. =09 Bryan =09 -----Original Message----- From: Austin Schutz [mailto: te...@of...] Sent: Thursday, March 15, 2007 2:40 PM To: Bryan Cox Cc: Bradford Ritchie; exp...@li...=20 Subject: Re: [Expectperl-discuss] Expect.pm & sftp =09 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:=20 > > -> spawn id(4): Does `' > -> match: > -> pattern #1: -re `(?-xism:ame.*:)'? No. > -> pattern #2: -re `(?-xism:assword:)'? No. > -> pattern #3: -re `(?-xism:ftp>)'? No.=20 > -> pattern #4: -re `(?-xism:(\n)|(\r))'? No. > -> Waiting for new data (10 seconds)... > -> TIMEOUT > =09 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: =09 #!/usr/bin/perl use Expect;=20 =09 # usage: test.pl <[username@]host> <password> =09 $sftp =3D Expect->spawn('sftp ' . $ARGV[0]); $sftp->exp_internal(1); $sftp->expect(10, 'ord: '); print $sftp $ARGV[1]."\r"; $sftp->expect(10,=20 'sftp> '); print $sftp "ls\r"; $sftp->expect(10, 'sftp> '); print "Files:" . $sftp->before(); =09 It's important to make sure you have received all the output=20 from the remote host before sending it anything. It may flush its buffers before reading, thereby dumping whatever you thought you sent it. =09 Austin =09 |
From: Vladimir K. <ma...@ma...> - 2007-03-21 11:04:54
|
Hello, I have same problem, Expect not working in custom environment, probably because of stdin, stdout redirections. I'm using mod_perl, and simple expect scenario works perfect in shell and not at all in mod_perl i'm trying to connect server side and do some data exchange. server: while :; do nc -l -p333 -c'echo READY; read RESP; echo READY2; sleep 10'; echo Exited; done (listening at 333 port, sending READY on connect and READY2 on first line receive) my script: use Expect; my $myhandle = new Expect; $myhandle->log_user(0); $myhandle->spawn("nc 192.168.1.11 333"); $myhandle->expect(10, [ timeout => sub { print STDERR "timeout\n" } ], [ eof => sub { print STDERR "eof\n" } ], [ qr/READY[\r\n]+/ => sub { print STDERR "READY\n" } ], ); $myhandle->send("TEST\n"); $myhandle->expect(10, [ timeout => sub { print STDERR "timeout\n" } ], [ eof => sub { print STDERR "eof\n" } ], [ qr/READY2[\r\n]+ => sub { print STDERR "READY2\n" } ], ); from shell it shows: READY READY2 from mod_perl it shows: READY timeout so it hanging just after first data sent to server :( Bryan Cox wrote: > > Brad and Austin, > > I've finally figured this thing out (sort of). Expect works fine in a > "normal" environment. > > We have a utility built in-house that we use to log the output of our > scripts. That utility does some forking, redirection of stdin & stdout, > and unbuffering before I make my Expect call. Between the two modules, > there's just one too many redirects or something. I'm not sure if I'll > ever get it sorted out to the point where I can make them work together, > but they work fine independently. > > I've appreciated your help, and hope I can return the favor some time. > > Bryan > > -- View this message in context: http://www.nabble.com/Expect.pm---sftp-tf3398274.html#a9591652 Sent from the Perl - Expectperl-Discuss mailing list archive at Nabble.com. |