xorl has asked for the wisdom of the Perl Monks concerning the following question:

I have this script where I'm trying to scp a file from one box to my home box.

I think I set up the whole thing with ssh-keygen correctly. At least from a command prompt, I and do ssh remotebox and I'm logged in without ever being prompted for a password (this only works on my home box not when I'm on another box).

So my script is really simple.

use Net::SCP; my $scp = Net::SCP->new("10.33.1.75", "xorl") or die("COULD NOT SCP"); $scp->scp("/export/home/xorl/websterproject/xferlist.txt", "/tmp/webst +erproject_xfer.txt") or die("TRANSFER FAILED");

Now it always dies with "TRANSFER FAILED" /tmp/websterproject_xfer.txt is sometimes created as an empty file.

I believe the permissions are correct on xferlist.txt I can from a command prompt do scp 10.33.1.75:/export/home/xorl/websterproject/xferlist.txt /tmp/websterproject_xfer.txtand everything works fine (it never asks me for a password).

So now I'm trying to figure how do I see what exaclty is going on inside of Net::SSH. I tried running the script with -d but I was quickly over my head. It looked like to me everything was going fine and then all of a sudden kaboom it dies.

So can anyone help me figure out what the problem is and how to fix it? Do I need to spend much time with the debugger?

Thanks.

Replies are listed 'Best First'.
Re: How do I debug a problem with Net:SSH
by injunjoel (Priest) on Nov 15, 2005 at 23:19 UTC
    Greetings,
    you might want to check the errstr Attribute from your $scp->scp() call.
    From docs:
    ... Returns false and sets the errstr attribute if there is an error.

    So something like the following perhaps untested
    $scp->scp( "/export/home/xorl/websterproject/xferlist.txt", "/tmp/websterproject_xfer.txt" ) or die $scp->{errstr}."\n";


    -InjunJoel
    "I do not feel obliged to believe that the same God who endowed us with sense, reason and intellect has intended us to forego their use." -Galileo

      Thanks but now I'm almost as perplexed as before.

      cp: cannot stat `/export/home/xorl/websterproject/xferlist.txt': No such file or directory

      Thinking I might need to tell it to look on the remote box I tried $scp->scp("10.33.1.75:/export/home/xorl/websterproject/xferlist.txt", "/tmp/websterproject_xfer.txt"); and I got

      Warning: something's wrong at ./getxfers.pl line 7. (which is the scp line)

      I then tried using the alternate $scp->get() syntax and got same something's wrong warning :(

      Now just to be sure I ssh'ed to the remote box and made sure the file exists, stat showed that the file exists with 644 permissions and my Uid and Gid.

      Now I have more information than before, but I feel more lost in the dark than ever. *sigh*

      Can anyone shed some light on this? Thanks again

Re: How do I debug a problem with Net:SSH
by dimishome (Beadle) on Nov 15, 2005 at 23:08 UTC
    You can add a warn statement to find out why it failed. Something like this.
    warn $scp->{errstr};
    Then you can check your logs to see what the error actually is.
Net::SCP and Net::SCP::Expect in the same script
by xorl (Deacon) on Nov 16, 2005 at 13:17 UTC

    Oooh I think I just found something interesting...

    Later in the script I scp the file to another server. I have to use Net::SCP::Expect for this server since the whole key thing isn't set up. So my very first line of the script after the #! is use Net::SCP::Expect. When I commented that out, everything worked fine for getting the file from the first server.

    Can I not use Net::SCP and Net::SCP:Expect in the same script??