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

I'm using Net::SFTP and it seems to work fine for the simple things. However, any methods that return handles (e.g., do_open, do_opendir) always return undef with no error messages. When I add debug, I see each one getting an ID but the internal get_handle call that converts the IDs to handles returns nothing. That's as far as I've gone so far. Any ideas? This is an SSH2 environment.

Replies are listed 'Best First'.
Re: Net::SFTP methods that return handles
by tilly (Archbishop) on Oct 24, 2004 at 02:03 UTC
    I have never used this module. But from the documentation it looks like it is supposed to do that - just return undef and no information on failure. Which seems pretty useless.

    One option is to email the author and ask about it. You may find out that he had a reason to not throw an error. For instance it may be that that call is not well supported by sftp servers, so failure isn't really viewed as an error.

    Another option is to modify your copy with various debug statements and see if you can figure out where it is deciding that things didn't work. You may be able to get it to print out a transcript of the actual interaction. If you go that path then you should be able to find out why it isn't working. Of course if the problem turns out to be that the server doesn't support the command, that won't get you very far.

    The third option is to find another approach for whatever you want to do.

    My approach would be to file a bug about the need for better feedback from the module on why things didn't work, and then I'd proceed to find a workaround for whatever I need to do.

      Ahead of you there ;-)

      I contacted the author who said he no longer maintains it. He directed me to the mailing list. I posted there but there have been zero posts or responses all day. I guess it's a pretty slow mailing list -- all Perl/SSH talk.

      I added more debug and have the SSH buffer being dumped to some degree. Now I need to find documentation on the protocol so I can try and interpret it. Haven't had time for that yet.

        Well here is a draft of the standard that the module refers to. That should describe the protocol.
Re: Net::SFTP methods that return handles
by steves (Curate) on Oct 25, 2004 at 13:09 UTC

    Using the documentation tilly dug up I was able to add more debugging. It turns out the handles are defined. They're just not printable. The first three handles I get, as bytes are:

    00 00 00 00 00 00 00 01 00 00 00 02
    I was debugging like this, expecting to see something:
    my $h = $sftp->do_open($file, SSH2_FXF_READ); print "handle=$h\n";
    ... and not seeing anything. Not a complete waste of time since I learned a bit about the protocol. And maybe this prevents someone else from wasting a few hours like I did.