Reputation: 1
I found the following problem to use net/sftp:
undefined method `put_file' for #<Net::SFTP::Session:0x00000001b40298>
(NoMethodError)
sftp.rb:17:in `block in <main>': undefined method `put_file' for #<Net::SFTP::Session:0x00000000b70138> (NoMethodError)
from /opt/ruby/lib/ruby/gems/1.9.1/gems/net-sftp-2.0.5/lib/net/sftp/session.rb:939:in `call'
from /opt/ruby/lib/ruby/gems/1.9.1/gems/net-sftp-2.0.5/lib/net/sftp/session.rb:939:in `block in do_version'
from /opt/ruby/lib/ruby/gems/1.9.1/gems/net-sftp-2.0.5/lib/net/sftp/session.rb:939:in `each'
from /opt/ruby/lib/ruby/gems/1.9.1/gems/net-sftp-2.0.5/lib/net/sftp/session.rb:939:in `do_version'
from /opt/ruby/lib/ruby/gems/1.9.1/gems/net-sftp-2.0.5/lib/net/sftp/session.rb:909:in `when_channel_polled'
from /opt/ruby/lib/ruby/gems/1.9.1/gems/net-ssh-2.1.4/lib/net/ssh/connection/channel.rb:311:in `call'
from /opt/ruby/lib/ruby/gems/1.9.1/gems/net-ssh-2.1.4/lib/net/ssh/connection/channel.rb:311:in `process'
from /opt/ruby/lib/ruby/gems/1.9.1/gems/net-ssh-2.1.4/lib/net/ssh/connection/session.rb:214:in `block in preprocess'
from /opt/ruby/lib/ruby/gems/1.9.1/gems/net-ssh-2.1.4/lib/net/ssh/connection/session.rb:214:in `each'
from /opt/ruby/lib/ruby/gems/1.9.1/gems/net-ssh-2.1.4/lib/net/ssh/connection/session.rb:214:in `preprocess'
from /opt/ruby/lib/ruby/gems/1.9.1/gems/net-ssh-2.1.4/lib/net/ssh/connection/session.rb:197:in `process'
from /opt/ruby/lib/ruby/gems/1.9.1/gems/net-ssh-2.1.4/lib/net/ssh/connection/session.rb:161:in `block in loop'
from /opt/ruby/lib/ruby/gems/1.9.1/gems/net-ssh-2.1.4/lib/net/ssh/connection/session.rb:161:in `loop'
from /opt/ruby/lib/ruby/gems/1.9.1/gems/net-ssh-2.1.4/lib/net/ssh/connection/session.rb:161:in `loop'
from /opt/ruby/lib/ruby/gems/1.9.1/gems/net-sftp-2.0.5/lib/net/sftp/session.rb:802:in `loop'
from /opt/ruby/lib/ruby/gems/1.9.1/gems/net-sftp-2.0.5/lib/net/sftp/session.rb:787:in `connect!'
from /opt/ruby/lib/ruby/gems/1.9.1/gems/net-sftp-2.0.5/lib/net/sftp.rb:32:in `start'
from sftp.rb:16:in `<main>'
But the module could be loaded without problem:
2011.07.08|17:12:07~/lin/Ruby>irb
irb(main):001:0> require 'net/ssh'
=> true
irb(main):002:0> require 'net/sftp'
=> true
irb(main):003:0>
By the way, my RUBYLIB is:
2011.07.08|17:15:33~/lin/Ruby>echo $RUBYLIB
/opt/ruby/lib/ruby/1.9.1/
Thanks! Dan
P.S:
require 'net/ssh'
require 'net/sftp'
host="localhost"
src_file="/etc/services"
dst_file="~/services"
Net::SFTP.start(host, ENV["USER"]) do |sftp|
sftp.put_file(src_file, dst_file)
end
......
Upvotes: 0
Views: 1024
Reputation: 11
Check your version. Net::SFTP 2 doesn't have put_file
anymore. Use upload
instead.
Upvotes: 1
Reputation: 46667
Net::SFTP does not have a put_file
method. See the full documentation for Net::SFTP.
Did you perhaps mean sftp.upload
or sftp.upload!
?
Upvotes: 1