Ruby NET::SCP 和自定义端口

发布于 2024-10-22 00:59:32 字数 501 浏览 5 评论 0原文

我正在尝试使用 Net::SCP 为 ssh 连接定义自定义端口,但到目前为止还没有运气。

下面是我如何尝试从具有自定义 ssh 端口的服务器下载远程文件的示例:

require "rubygems"
require 'net/scp'
Net::SCP.download!("www.server.com", "user", "/opt/platform/upload/projects/file.txt", "/tmp/bb.pdf",{:password => "mypassword",:port => 22202})

我收到的错误消息是:

 Errno::ECONNREFUSED: Connection refused - connect(2)

服务器日志中没有有关 ssh 连接的条目,因此我假设 Net: :SCP 没有使用我的自定义端口。

有什么建议给我吗?

问候,亚历克斯

I'm trying to define a custom port for the ssh connection using Net::SCP, but without luck so far.

Here's an example how I'm trying to download a remote file from a server with a custom ssh port:

require "rubygems"
require 'net/scp'
Net::SCP.download!("www.server.com", "user", "/opt/platform/upload/projects/file.txt", "/tmp/bb.pdf",{:password => "mypassword",:port => 22202})

The error message I'm getting is:

 Errno::ECONNREFUSED: Connection refused - connect(2)

There are no entries in the server logs regarding the ssh connection, so I assume that Net::SCP isn't using my custom port.

Any tips for me ?

Regards, Alex

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无力看清 2024-10-29 00:59:32

嗯,我自己找到了解决方案。

require "rubygems"
require "net/scp"
Net::SSH.start("www.myserver.com", "theuser", {:password => "whateverpwd",:port => 22212}) do |ssh|
  ssh.scp.download! "/opt/platform/upload/projects/my.pdf", "/tmp/bb.pdf"
end

Well, I've found the solution myself.

require "rubygems"
require "net/scp"
Net::SSH.start("www.myserver.com", "theuser", {:password => "whateverpwd",:port => 22212}) do |ssh|
  ssh.scp.download! "/opt/platform/upload/projects/my.pdf", "/tmp/bb.pdf"
end
酒解孤独 2024-10-29 00:59:32

我还在非标准端口上保留 SSH 并使用 SCP,如下所示:

Net::SCP.upload!( "foo.net", "user", the_file, the_file, :ssh => { :keys => @keys, :port => the_port } )

Works like a champ。我还使用基于密钥的身份验证,因此密钥参数与端口一起传递。

I also keep SSH on a non-standard port and use SCP like so:

Net::SCP.upload!( "foo.net", "user", the_file, the_file, :ssh => { :keys => @keys, :port => the_port } )

Works like a champ. I also use key-based authentication, hence the keys parameter getting passed along with the port.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文