I think I misread your code and sample output anyway. You are getting connected, but the connection isn't doing what you want? Is that closer to what's happening?

A quick note regarding Net::SSH::Perl and myself: I'm no expert on this project, and I won't claim to be. I'm hoping if you haven't stumbled over some solution on your own that more feet will stumble faster. :-)

What happens if you use a command other than 'exit'? My first guess is that you're not getting the command you think you are. An explanation of that thought will be below, but checking the return values on functions (especially those involving more than one machine) should probably be a habit. My guess after that, I think, would be that the exit command on your remote end doesn't close the connection, which you'd have to do manually. Does the connection get closed when you issue the exit command when ssh'ed in directly?

I'm not sure if you've tried it already, but there's Net::SSH, Net::SFTP, and Net::SSH::Perl mailing list that's archived at the modules' Sourceforge project. There's a good chance someone there might have had similar issues. Please let us know if you find something there that helps.

I notice you're not checking the return value on the cmd() method. According to a message on the afore-mentioned archive, at least one person thinks shell builtins don't work with cmd(). I'd guess the exit command wouldn't be a separate executable. Over on CPAN::Forum this message alludes to needing use_pty enforced on cmd() as well as shell() in order to use a shell on the remote end non-interactively. Net::SSH::Perl::SSH2 appears not to do this, and in fact a quick check of Net::SSH::Perl would seem to confirm it.

Given the above information, I'd try using the shell() method and typing 'exit' as a command interactively just to make sure it works there. If that works and I really needed to make it work from the cmd() method, I'd figure out what it so different between shell() and cmd(). Then perhaps I'd subclass Net::SSH::Perl::SSH2 to make cmd() a little more like shell(), or send a patch to the maintainers that enables such use.


In reply to Re^3: net::ssh::Perl connecting to f-secure ssh server by mr_mischief
in thread net::ssh::Perl connecting to f-secure ssh server by tweetiepooh

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.