Kyle Rabe
2007-Nov-30 11:46 UTC
[Net-ssh-users] Truncated results when reading from standard output
Hello! I''d like to do something *very* simple using Net::SSH - get a
directory listing. This is the code that I''m trying to use:
1 require ''net/ssh''
2
3 Net::SSH.start(''host'', ''user'',
''pass'') do |session|
4
5 session.process.popen3("ls ~/catalog/public/images/catalog") do
|input, output, error|
6 puts output.read
7 end
8
9 end
That''s it. When I execute that code, I start to get the listing, but
it
doesn''t complete (there are many, many files in this directory, and I
get a
list of about 50 - it''s the same each time). It seems to me as if
something is interrupting the ''ls'' process, but I guess that a
bunch of
things could be going wrong. I''ve tried using channels and
process.exec
etc., but I tend to get the same results. If I run this code in irb, I get
the same output followed by a LOT of other output describing the session
(many, many screens worth). I can ssh into this server just fine from
bash.
Have I forgotten to set something up? I can execute more simple commands,
such as those in the documentation, without problems. Is my code terrible?
It seems like it should be so easy...
Thank you for your help!
-Kyle
Andy Koch
2007-Nov-30 11:48 UTC
[Net-ssh-users] Truncated results when reading from standard
Kyle Rabe wrote:> Hello! I''d like to do something *very* simple using Net::SSH - get a > directory listing. This is the code that I''m trying to use: > > 1 require ''net/ssh'' > 2 > 3 Net::SSH.start(''host'', ''user'', ''pass'') do |session| > 4 > 5 session.process.popen3("ls ~/catalog/public/images/catalog") do > |input, output, error| > 6 puts output.read > 7 end > 8 > 9 end > > That''s it. When I execute that code, I start to get the listing, but it > doesn''t complete (there are many, many files in this directory, and I get a > list of about 50 - it''s the same each time). It seems to me as if > something is interrupting the ''ls'' process, but I guess that a bunch of > things could be going wrong. I''ve tried using channels and process.exec > etc., but I tend to get the same results. If I run this code in irb, I get > the same output followed by a LOT of other output describing the session > (many, many screens worth). I can ssh into this server just fine from > bash. > > Have I forgotten to set something up? I can execute more simple commands, > such as those in the documentation, without problems. Is my code terrible? > It seems like it should be so easy... > > Thank you for your help! > > -Kyle > > _______________________________________________ > Net-ssh-users mailing list > Net-ssh-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/net-ssh-users > >why not use net::sftp? "http://net-ssh.rubyforge.org/sftp/faq.html#2202692" -- Andy Koch, Web Applications Developer
That did it. Thanks for the link! -Kyle On Fri, 30 Nov 2007 11:48:37 -0800, Andy Koch <andy.koch at pc-doctor.com> wrote:> > > Kyle Rabe wrote: >> Hello! I''d like to do something *very* simple using Net::SSH - get a >> directory listing. This is the code that I''m trying to use: >> >> 1 require ''net/ssh'' >> 2 >> 3 Net::SSH.start(''host'', ''user'', ''pass'') do |session| >> 4 >> 5 session.process.popen3("ls ~/catalog/public/images/catalog") do >> |input, output, error| >> 6 puts output.read >> 7 end >> 8 >> 9 end >> >> That''s it. When I execute that code, I start to get the listing, but it >> doesn''t complete (there are many, many files in this directory, and I > get a >> list of about 50 - it''s the same each time). It seems to me as if >> something is interrupting the ''ls'' process, but I guess that a bunch of >> things could be going wrong. I''ve tried using channels and process.exec >> etc., but I tend to get the same results. If I run this code in irb, I > get >> the same output followed by a LOT of other output describing the session >> (many, many screens worth). I can ssh into this server just fine from >> bash. >> >> Have I forgotten to set something up? I can execute more simple > commands, >> such as those in the documentation, without problems. Is my code > terrible? >> It seems like it should be so easy... >> >> Thank you for your help! >> >> -Kyle >> >> _______________________________________________ >> Net-ssh-users mailing list >> Net-ssh-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/net-ssh-users >> >> > > why not use net::sftp? > > "http://net-ssh.rubyforge.org/sftp/faq.html#2202692" > > -- > Andy Koch, Web Applications Developer > > _______________________________________________ > Net-ssh-users mailing list > Net-ssh-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/net-ssh-users