如何在没有发送文件的情况下检测远程主机上的scp服务是否可用?

2 perl scp

您能否建议一种方法来检测服务器上的scp服务是否可用而无需帐户和/或密码?

我想知道如何判断

 Net::SCP->new( "hostname", "username" );
Run Code Online (Sandbox Code Playgroud)

由于远程主机上的服务不可用或者由于身份验证失败,函数无法连接到远程.

Cha*_*ick 5

sshd将在端口22上运行.远程登录它以查看它是否响应.

要在不编写代码的情况下检查服务器,请在命令行中键入:

telnet host.example.com 22
Run Code Online (Sandbox Code Playgroud)

如果ssh服务可用,响应将如下所示:

Trying host.example.com...
Connected to host.example.com.
Escape character is '^]'.
SSH-2.0-OpenSSH_5.1p1 Debian-5ubuntu1
Run Code Online (Sandbox Code Playgroud)

如果没有,你会看到:

Trying host.example.com...
telnet: Unable to connect to remote host: Connection refused
Run Code Online (Sandbox Code Playgroud)