in reply to Re^12: SSH2 for windows
in thread SSH2 for windows

Hi Perl Monks and Rob,
i have installed libssh2-0.14 from http://www.libssh2.org>, openssl-0.9.8b and zlib-1.2.3 to linux box.
working fine.just check the code and output.We can also hold the session.
#!/usr/bin/perl use warnings; use strict; use Net::SSH2; my $ssh2 = Net::SSH2->new(); $ssh2->connect('$hostname') or die "Unable to connect Host $@ \n"; $ssh2->auth_password('$user','$passwd') or die "Unable to login $@ \n" +; my $chan2 = $ssh2->channel(); $chan2->shell(); print $chan2 "cd shanthi_backup\n"; print $chan2 "pwd\n"; print "LINE : $_" while <$chan2>; print $chan2 "ls -lrt\n"; print "LINE : $_" while <$chan2>;
output
LINE : Running .profile...
LINE : YOU HAVE NEW MAIL
LINE : /home/shanthi/shanthi_backup
LINE : total 6873
LINE : -rw-r--r-- 1 shanthi ccdata3 83917 Dec 21 07:46 cmtool_latest.pl
LINE : -r-xr-xr-x 1 shanthi ccdata3 22141 Jan 04 06:07 synctree
LINE : drwxrwxr-x 2 shanthi ccdata3 4096 Jan 05 07:57 perl
LINE : -rwxrwxr-x 1 shanthi ccdata3 2040 Jan 05 07:57 ctrlmfindnew.pl
LINE : -rw-rw-r-- 1 shanthi ccdata3 25 Jan 27 14:15 test.pl
LINE : -rw-rw-r-- 1 shanthi ccdata1 0 Feb 07 13:04 a.txt
LINE : -rwxr-xr-x 1 shanthi ccdata3 7193 Feb 07 13:07 csv.pl

Replies are listed 'Best First'.
Re^14: SSH2 for windows
by syphilis (Archbishop) on Feb 10, 2007 at 07:00 UTC
    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
      Hi Robs,
      How is your health now?.
      Net::SSH2 0.10,will it work for my requirements.