Reputation: 608
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)
Upvotes: 0
Views: 186
Reputation: 18845
One of the big advantages of Ruby is, that it relies on just a couple of basic things to implement different functionalities. One of the things where this taken to an extreme is IO. Borrowed from the UNIX principle "everything is a file", in Ruby "everything is IO".
So the error Errno::ENOENT - No such file or directory - getaddrinfo:
is just a generic IO error, telling you that the address http://www.domain.ch/path/to/directory
could not be found. It would be even easier to spot this error if you had provided the line-numbers in your code, as they map 1 to 1 to the stack-trace you posted.
From what I know about SSH, it does not care about URLs. It cares about host
and user
, optionally about a password, but it's better to use key based authentication.
So if you look at the net/ssh example, you will see that you have to pass the host and not an URL. In your example this would translate to something like this:
require 'net/ssh'
Net::SSH.start('www.domain.ch', 'gast') do |ssh|
ssh.exec!('ls path/to/directory')
end
Upvotes: 1