Net::SSH2 scp_put not working!

Discussion in 'Perl Misc' started by Krishna Chaitanya, Feb 17, 2009.

  1. Is there a case I'm missing where blocking(0) leads to successful
    execution and read of a command through $channel->shell() and setting
    blocking(1) makes it hang indefinitely?

    I've understood polling and related topics, thanks to all your inputs,
    but it defeats me completely why setting blocking(1) would hang any
    command forever. What am I missing here conceptually?

    Many thanks, everyone, for your edifying words...
    Krishna Chaitanya, Mar 2, 2009
    1. Advertisements

  2. Also, can anyone please take this program and execute at their end and
    tell me if they succeeded in getting the command output?


    use warnings;
    use strict;

    use Net::SSH2;

    my $ssh2 = Net::SSH2->new();

    $ssh2->connect(<an IP you can connect to>) or die;

    if ($ssh2->auth_password(<username>,<password>)) {
    print "Authorization successful\n";
    my $chan2 = $ssh2->channel();
    print $chan2 "uname -a\n";
    print "LINE : $_" while <$chan2>;
    $ssh2->scp_put(<Path-to-any-file-to-be-scp-ed>) or warn "Could
    not scp the file <filename> ";
    } else {
    print "Authorization failure\n";

    Thanks again!
    Krishna Chaitanya, Mar 2, 2009
    1. Advertisements

  3. The first problem I had was that my server doesn't allow 'password'
    Thanks, I will.
    I had the same feeling when I saw calls to poll in READLINE and GETC
    (my assumption - it could be silly - is that poll is used in case of
    non-blocking I/O), thanks for confirming. How could we attract the
    module maintainer's attention w.r.t this?
    Sorry for being thick...can I verify this 250ms thing by checking
    response time from a ping? Or is there another way for me?
    Hmm.....point taken. So should I instead be using a series of exec? Is
    there no way to tell a shell to let me know it's done with the command
    processing (some kind of a command-specific EOF)?

    Thanks a lot, Ben.
    Krishna Chaitanya, Mar 3, 2009
  4. did <> manage to get EOF from shell in case of blocking
    (0) .... ?
    Krishna Chaitanya, Mar 3, 2009
  5. This is one reason I gave up on trying to use Net::SSH2 and went
    back to Net::SSH::perl instead. I was running a command that would
    not return output quickly enough. With blocking in place, it never
    returned. With blocking turned off, I couldn't reliably detect when
    the remote command completed -- the readline returned undef any time
    there was no output waiting to be read, and I couldn't get detection
    of listener_closed or channel_closed to work reliably.

    Net::SSH::perl doesn't have the scp functions, but you may be able to
    work around that. I use cat >file <<_END_OF_INPUT_ to create remote
    files -- this could fail in the general case, of course, but the
    set of files I needed to process was restricted enough that I knew
    it would work for me.

    Gary Ansok
    Gary E. Ansok, Mar 3, 2009
  6. Well, perhaps I wasn't doing it correctly. I was creating a new
    channel and then using $chan->exec($cmd), but was having trouble
    getting the complete output and detecting when the remote command
    finished. (The remote command could be as simple as a script with
    "sleep 2; ls".)

    As I mentioned, I had an existing version using Net::SSH::perl, so there
    wasn't a massive need to switch over. We were having performance issues,
    but ended up solving those by upgrading the bigint libraries (I think
    there was some glitch in the installation of the eearlier versions).
    Thanks for the info -- I'd looked at that in the past, but at the time
    we were having performance issues centered on the initial connection,
    so only doing one connection was important. (I don't see a way to use
    an existing Net::SSH::perl connection in Net::SFTP, or a supported way to
    use the connection from Net::SFTP for other uses.) Still, it's something
    I'll look at again if I need to update this code.

    Gary E. Ansok, Mar 3, 2009
  7. [ OP missed attribution ]
    Or shape your network. That goes beyond the scope of c.l.p.m. though.

    Eric Pozharski, Mar 3, 2009
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.