Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

NET::SCP::Expect

Status
Not open for further replies.

lpaulose

Programmer
Joined
Feb 25, 2005
Messages
4
Location
US
I am using NET::SCP::Expect to copy files from a remote server. The scp() commands seems to abruptly quit when the file is not available on the remote server. Could someone provide me an example on how to use the method error_handler() that comes with this module?

Thanks!
 
Could you provide us with your code to check it out?
Then we might be able to help. Hopefully :)
 
I thought I got it to work but it seems it still errors out.

This is the code I'm using to connect where the sub routine catchError is user defined:

my $scpe = Net::SCP::Expect->new(host=>"$import_host",user=>"$import_user",password=>"$import_pwd",auto_yes=>1) or $scp_err=1;
$scpe->host("$import_host") or $scp_err=1;
$scpe->user("$import_user") or $scp_err =1;
$scpe->login("$import_user","$import_pwd") or $scp_err=1;
$scpe->error_handler(catchError());
$scpe->scp("$import_file","$local_file") or $scp_err=1;

This is the error I'm currently getting
Can't use string ("1") as a subroutine ref while "strict refs" in use at /usr/lib/perl5/site_perl/5.8.0/Net/SCP/Expect.pm line 226.

The catchError subroutine is defined above it call.

Any help would be much appreciated. Thanks
 
Can you check for the existence of the file before copying?

--Paul

cigless ...
 
I don't know how to check the existance of a file on a remote server before copying. Not sure what the code is for checking existance of file on a remote server. That's why I had to try calling the error_handler method. It would be of great help if that could be done via the script prior to copying via scp
 
Is there a dir method, or ls method to get the contents of a directory, parse that, and if file exists, then download

--Paul

cigless ...
 
It doesn't look like the perl module scp has any such options.
 
Net::SSH might be a way to check if the file exists?
--Paul

cigless ...
 
my $scpe = Net::SCP::Expect->new(host=>"$import_host",user=>"$import_user",password=>"$import_pwd",auto_yes=>1) or $scp_err=1;

You already set thehost and user and the login why do you set them again?

$scpe->host("$import_host") or $scp_err=1;
$scpe->user("$import_user") or $scp_err =1;
$scpe->login("$import_user","$import_pwd") or $scp_err=1;

and what exactly do you want to do with this scalar '$scp_err' ?

$scpe->error_handler(catchError());
$scpe->scp("$import_file","$local_file") or $scp_err=1;

let as take a look at this catchError() of yours

why don't you try to do it like the examples that the manual has?

TIMTOWTDI
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top