0

Ruby 2.0, Rails 4. I made a site which serves static files. I used

 Dir.glob 

to list static files Now I have to save the files outside the app because the slugsize in Heroku will be too big otherwise

For this reason, i would like a directory listing of a public web folder. (Served by apache server)

I tried: Gemfile:

gem 'net-ssh'

Controller:

def index
  require 'net/ssh'

  ssh = Net::SSH.start( 'http://www.domain.ch/path/to/directory', 'gast')
  @files =ssh.exec!( 'ls . ').split("\n")
  ssh.close
end

This raised the error:

 Errno::ENOENT - No such file or directory - getaddrinfo:
 net-ssh (2.7.0) lib/net/ssh/transport/session.rb:67:in `block in initialize'
 /home/benutzer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/timeout.rb:52:in `timeout'
 /home/benutzer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/timeout.rb:97:in `timeout'
 net-ssh (2.7.0) lib/net/ssh/transport/session.rb:67:in `initialize'
 net-ssh (2.7.0) lib/net/ssh.rb:200:in `start'
 ...

I never heard of a file called getaddrinfo

The answer on this thread `initialize': No such file or directory - getaddrinfo (Errno::ENOENT) when Rails new app (updating rvm) didnt solve the problem.

Additional info:

$gem -v bundler
2.0.5
$rvm - v
rvm 1.21.12 (stable)

$rvm - v
rvm 1.23.9 (master)
4

1 回答 1

1

Ruby 的一大优点是,它只依赖几个基本的东西来实现不同的功能。其中一个极端的事情是 IO。借用了 UNIX 原则“一切都是文件”,在 Ruby 中“一切都是 IO”。

所以这个错误Errno::ENOENT - No such file or directory - getaddrinfo:只是一个通用的IO错误,告诉你http://www.domain.ch/path/to/directory找不到地址。如果您在代码中提供了行号,则更容易发现此错误,因为它们将 1 到 1 映射到您发布的堆栈跟踪。

根据我对 SSH 的了解,它不关心 URL。它关心hostand user,可选地关心密码,但最好使用基于密钥的身份验证。

因此,如果您查看net/ssh 示例,您将看到您必须传递主机而不是 URL。在您的示例中,这将转化为如下内容:

require 'net/ssh'

Net::SSH.start('www.domain.ch', 'gast') do |ssh|
  ssh.exec!('ls path/to/directory')
end
于 2013-10-20T14:47:31.680 回答