您能否建议一种无需帐户和/或密码即可检测服务器上是否可用 scp 服务的方法?
我想弄清楚如何判断
Net::SCP->new( "hostname", "username" );
由于远程主机上的服务不可用或由于身份验证失败,函数无法连接到远程。
sshd 将在端口 22 上运行。Telnet 到它以查看它是否响应。
要在不编码的情况下检查服务器,请在命令行中键入:
telnet host.example.com 22
如果 ssh 服务可用,响应将如下所示:
Trying host.example.com...
Connected to host.example.com.
Escape character is '^]'.
SSH-2.0-OpenSSH_5.1p1 Debian-5ubuntu1
如果没有,您将看到:
Trying host.example.com...
telnet: Unable to connect to remote host: Connection refused
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.
使用 Net::SSH2 或 Net::OpenSSH 而不是 Net::SCP
查德威克在上面是正确的,但是当您认为它应该工作并且 sshd 正在运行时,请检查以下内容:
路线好吗?尝试
ping host.example.com
host.example.com 上的 hosts.allow 文件是否设置为允许连接?如果您使用 DNS 名称,它必须能够解析传入连接。
host.example.com 上是否运行防火墙?尝试
iptables -L
在 Linux 上或在 Windows 上检查防火墙。