<?xml version="1.0" encoding="windows-1252"?>
<node id="1003982" title="Re^2: Capturing SSH output in an array." created="2012-11-15 04:37:07" updated="2012-11-15 04:37:07">
<type id="11">
note</type>
<author id="446266">
salva</author>
<data>
<field name="doctext">
Net::SSH::Any is still a work on progress and the documentation is quite lacking, but the API is mostly a subset of that of [mod://Net::OpenSSH] (IIRC, &lt;c&gt;new, system, capture, capture2, error&lt;/c&gt; and &lt;c&gt;scp&lt;/c&gt; methods are supported) so you should read its docs.

&lt;p&gt;The &lt;c&gt;new&lt;/c&gt; method returns always an object, even when the connection fails. You have to use the &lt;c&gt;error&lt;/c&gt; method to check for errors.

&lt;p&gt;In order to use public key authentication, use the constructor option &lt;c&gt;key_path&lt;/c&gt; to pass the path of the file containing the private key to Net::SSH::Any.

&lt;c&gt;
my $ssh = Net::SSH::Any-&gt;new($hostname, user =&gt; $user, key_path =&gt; "/home/$user/.ssh/id_dsa");
if ($ssh-&gt;error) {
    say "whee...something wrong here: " . $ssh-&gt;error;
}
else {
    say " I am connected to $hostname!!!";
    my @out = $ssh-&gt;capture($cmd);
    say "The files and directories of $username on $hostname are given below";
    say "@out";
}
&lt;/c&gt;

&lt;p&gt;&lt;b&gt;Update&lt;/b&gt;: BTW, the module should be as fast as any other SSH client implementation (i.e. PuTTY or OpenSSH). Connecting to some machine in the same (or a near) LAN should be a sub-second operation.

&lt;p&gt;Maybe sshd is configured on the Centos machine to use ident or your DNS configuration is broken or you have any other network problem or the host supporting the VM is overloaded.</field>
<field name="root_node">
1003801</field>
<field name="parent_node">
1003876</field>
</data>
</node>
