Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: Using Perl to do SCP

by Rhys (Pilgrim)
on Sep 15, 2004 at 16:03 UTC ( #391225=note: print w/replies, xml ) Need Help??

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.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://391225]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2021-03-02 08:44 GMT
Find Nodes?
    Voting Booth?
    My favorite kind of desktop background is:

    Results (41 votes). Check out past polls.