简体   繁体   English

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

[英]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? 您能否建议一种无需帐户和/或密码即可检测服务器上是否可以使用scp服务的方法?

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. 由于远程主机上服务不可用或身份验证失败,此功能无法连接到远程。

sshd would be running on port 22. Telnet to it to see if it is responding. sshd将在端口22上运行。Telnet到它以查看它是否在响应。

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: 如果ssh服务可用,响应将如下所示:

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

使用Net :: SSH2或Net :: OpenSSH代替Net :: SCP

Net::SCP doesn't use passwords unless you're using the interactive mode, it uses RSA or DSA keys. Net :: SCP除非使用交互模式,否则不使用密码,它使用RSA或DSA密钥。 At the point you use get() or put(), those functions will return a true or false on success or failure. 在使用get()或put()时,这些函数在成功或失败时将返回true或false。

You might wish to check out Net::SCP::Expect instead if you need to use passwords instead of key authentication. 如果您需要使用密码代替密钥验证,则可能希望签出Net :: SCP :: Expect。 The perldoc for both modules has good examples to follow. 这两个模块的perldoc都有很好的例子。

Chadwick has it correct above, but when you think it should work and sshd is running, then check the following: Chadwick在上面具有正确的说明,但是当您认为它应该可以运行并且sshd正在运行时,请检查以下内容:

  1. Route OK? 路线确定吗? Try 尝试

     ping host.example.com 
  2. Is hosts.allow file on host.example.com set to allow the connection? host.example.com上的hosts.allow文件是否设置为允许连接? It has to be able to resolve the incoming connection if you use DNS names. 如果使用DNS名称,它必须能够解析传入的连接。

  3. Is there a firewall running on host.example.com? host.example.com上是否运行防火墙? Try 尝试

     iptables -L 

    on Linux or check the firewall on Windows. 在Linux上或在Windows上检查防火墙。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM