当我尝试开始到我的debian ssh服务器并传输一个文件时,每次我都有一个非常奇怪的错误信息--‘Net::SSH.start’:Net::SSH::AuthenticationFailed,但是所有的认证数据都是正确的,我不知道是什么问题。有没有人面临同样的问题?代码是用ruby写的,使用的是net/ssh模块,下面是代码:
require 'rubygems'
require 'net/ssh'
def copy_file(session, source_path, destination_path=nil)
destination_path ||= source_path
cmd = %{cat > "#{destination_path.gsub('"', '\"')}"}
session.process.popen3(cmd) do |i, o, e|
puts "Copying #{source_path} to #{destination_path}... "
open(source_path) { |f| i.write(f.read) }
puts 'Done.'
end
end
Net::SSH.start("192.168.112.129",
:username=>'username',
:password=>'password') do |session|
copy_file(session, 'D:/test/1.txt')
copy_file(session, '/home/timur/Documents/new_file.rb"')
end发布于 2013-03-11 21:20:06
net/SSH2.6中没有:username选项,可以像参数一样设置:
Net::SSH.start('192.168.112.129', 'username', password: 'password') do |ssh|
foo
endhttps://stackoverflow.com/questions/15338968
复制相似问题