kishore
kishore

Reputation:

How can I detect if scp service is available at remote host with out sending the file?

Could you please suggest a way to detect if the scp service is available on a server without the need for an account and/or password?

I am trying to figure out how to tell if

 Net::SCP->new( "hostname", "username" );

function fails to connect to remote because of service is unavailable at remote host or because of authentication failure.

Upvotes: 2

Views: 2998

Answers (4)

dminear
dminear

Reputation: 111

Chadwick has it correct above, but when you think it should work and sshd is running, then check the following:

  1. Route OK? Try

    ping host.example.com
    
  2. Is hosts.allow file on host.example.com set to allow the connection? It has to be able to resolve the incoming connection if you use DNS names.

  3. Is there a firewall running on host.example.com? Try

    iptables -L
    

    on Linux or check the firewall on Windows.

Upvotes: 0

Chadwick
Chadwick

Reputation: 12663

sshd would be running on port 22. Telnet to it to see if it is responding.

To check the server without coding something up, at the command line, type:

telnet host.example.com 22

If the ssh service is available, the response will look something like this:

Trying host.example.com...
Connected to host.example.com.
Escape character is '^]'.
SSH-2.0-OpenSSH_5.1p1 Debian-5ubuntu1

If not, you'll see:

Trying host.example.com...
telnet: Unable to connect to remote host: Connection refused

Upvotes: 6

salva
salva

Reputation: 10242

use Net::SSH2 or Net::OpenSSH instead of Net::SCP

Upvotes: 1

markh
markh

Reputation: 793

Net::SCP doesn't use passwords unless you're using the interactive mode, it uses RSA or DSA keys. At the point you use get() or put(), those functions will return a true or false on success or failure.

You might wish to check out Net::SCP::Expect instead if you need to use passwords instead of key authentication. The perldoc for both modules has good examples to follow.

Upvotes: 1

Related Questions