kishore
kishore

Reputation: 167

How can I determine if scp is available from Perl?

In Net::SCP at which point do I need DSC or RSA keys (i.e when do I use the get or put functions)?. I would like to know the scp service is available without transferring the file.

Upvotes: 0

Views: 954

Answers (4)

Quadir
Quadir

Reputation: 271

If you are planning to use SSH using password authentication, consider Net::SSH::Perl.

Upvotes: 1

Alex Martelli
Alex Martelli

Reputation: 882411

Per the docs in CPAN, you need it before you even import that module, and I quote:

""" Q: How do you supply a password to connect with ssh within a perl script using the Net::SSH module?

A: You don't. Use RSA or DSA keys. See the ssh-keygen(1) manpage.

"""

In other words, NET::SCP is designed to use with "password-less" SSH authentication via pre-generated and propagated private/public key pairs.

Upvotes: 3

lexu
lexu

Reputation: 8849

Since Net::SCP is a wrapper to scp, you don't need to (meaning you can't) supply the keys to the script. You (or someone else) are expected to do the setup by configuring ssh before you attempt using it.

NET::SCP is not meant to be used 'ad hoc'. It requires ssh-configuration and exchange of keys.

EDIT incorporated ysth's comment

Upvotes: 1

ysth
ysth

Reputation: 98398

If all you want is to check if the remote system is listening on the ssh/scp port, you can try pinging:

use Net::Ping;
$p = Net::Ping->new("tcp", 2);
$p->port_number(scalar(getservbyname("ssh", "tcp")));
if ( $p->ping( $hostname ) ) {
    print "ok!";
}

You can use Net::SSH or Net::SSH::Expect or Net::SSH2 or Net::SSH::Perl if you have keys or password and want to verify that you can connect without actually transfering any files.

Upvotes: 1

Related Questions