http://qs321.pair.com?node_id=391225


in reply to Using Perl to do SCP

Okay, I did both of what I suggested to myself. :-) I wrote a new error_handler sub with use Data::Dumper, plus I wrote some extra code in there to clean up the data passed through @_. Here's what I used:

sub showme { use Data::Dumper; print Dumper(@_); print "\n"; foreach ( @_ ) { chomp $_; print "Thing is $_.\n"; } exit; }

As it turns out, the problem is the way the switch closes the connection at the end of the file transfer. Apparently, Net::SCP::Expect doesn't expect (pardon the pun) the string it gets. So here's the code I'm using (successfully, so far) in the production script to handle it:

sub scp_errors { use strict; my $line = shift; if ( $line =~ /Connection.+closed by remote host/ ) { # This is expected from an 8600. return(0); } else { # Get rid of CR and LF. $line =~ s/\012//g; $line =~ s/\015//g; print "Got error pulling file:\n"; print "\t", $line; print "\n"; return(1); } }

As far as I can tell, only one error line gets passed to the error handler. If this turns out not to be the case later, I'll have to change scp_errors to deal with multiple args.

--J