Yes - that works for me on linux, too. I changed $ssh2->connect('$hostname') ... to something valid. And I cd'd to /home/rob/pscrpt/net-ssh2 instead of shanthi_backup. That gave me the following output:
LINE : /home/rob/pscrpt/net-ssh2 LINE : total 12 LINE : -rw-r--r-- 1 rob rob 334 Dec 9 19:51 exec.pl LINE : -rw-r--r-- 1 rob rob 453 Dec 15 11:09 shell.p +l LINE : -rw-r--r-- 1 rob rob 443 Feb 10 15:05 shell2. +pl

Unfortunately, on Win32, doing while <$chan2> simply does not work. At least I can't get it to work - the script exits and produces no output. There's quite probably someone here who knows how to fix that - unfortunately, I don't.

Only way I could find of duplicating the result on Win32 was to code it this way:
use warnings; use strict; use Net::SSH2; my $buflen = 500; my $buf = '0' x $buflen; my $ssh2 = Net::SSH2->new(); $ssh2->connect('192.168.0.3') or die "Unable to connect Host $@ \n"; $ssh2->auth_password('user','password') or die "Unable to login $@ \n" +; my $chan2 = $ssh2->channel(); $chan2->blocking(1); $chan2->exec("cd /home/rob/pscrpt/net-ssh2 && pwd && ls -lrt"); $chan2->read($buf, $buflen); $chan2->close; chomp $buf; $buf =~ s/\n/\nLINE : /g; $buf = "LINE : " . $buf; print $buf, "\n";
That produces exactly the same output as I've shown above. It's obviously not ideal - for one thing you need to allocate a sufficiently large buffer in advance. If the buffer isn't big enough, you'll lose info.

Sorry, that's about the best I can offer at the moment.

Cheers,
Rob

In reply to Re^14: SSH2 for windows by syphilis
in thread SSH2 for windows by shanthiann

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.