【发布时间】:2011-04-03 01:52:30
【问题描述】:
我有一个小问题:我尝试使用 SCP 和 Ruby 将文件上传到使用私钥的服务器。代码如下:
def transfer_file(source_file, destination_file)
$log.info("ScpDP: Key=#{@key}")
Net::SCP.start(@host, @userName, :keys => @key ) do |scp|
scp.upload!(source_file,@folder + destination_file, :ssh => @key)
end
end
但是有一些问题,而不是私钥,因为我们将它用于日常目的,我收到以下日志错误:
I, [2010-08-24T11:21:27.247847 #14310] INFO -- : ScpDP: Key=/home/myself/.ssh/id_rsa
I, [2010-08-24T11:21:27.397971 #14310] INFO -- : SCP did not finish successfully (1) (Net::SCP::Error)
/usr/lib/ruby/gems/1.8/gems/net-scp-1.0.2/lib/net/scp.rb:351:in `start_command'
/usr/lib/ruby/gems/1.8/gems/net-ssh-2.0.11/lib/net/ssh/connection/channel.rb:585:in `call'
/usr/lib/ruby/gems/1.8/gems/net-ssh-2.0.11/lib/net/ssh/connection/channel.rb:585:in `do_close'
/usr/lib/ruby/gems/1.8/gems/net-ssh-2.0.11/lib/net/ssh/connection/session.rb:575:in `channel_close'
/usr/lib/ruby/gems/1.8/gems/net-ssh-2.0.11/lib/net/ssh/connection/session.rb:455:in `send'
/usr/lib/ruby/gems/1.8/gems/net-ssh-2.0.11/lib/net/ssh/connection/session.rb:455:in `dispatch_incoming_packets'
/usr/lib/ruby/gems/1.8/gems/net-ssh-2.0.11/lib/net/ssh/connection/session.rb:212:in `preprocess'
/usr/lib/ruby/gems/1.8/gems/net-ssh-2.0.11/lib/net/ssh/connection/session.rb:196:in `process'
/usr/lib/ruby/gems/1.8/gems/net-ssh-2.0.11/lib/net/ssh/connection/session.rb:160:in `loop'
/usr/lib/ruby/gems/1.8/gems/net-ssh-2.0.11/lib/net/ssh/connection/session.rb:160:in `loop_forever'
/usr/lib/ruby/gems/1.8/gems/net-ssh-2.0.11/lib/net/ssh/connection/session.rb:160:in `loop'
/usr/lib/ruby/gems/1.8/gems/net-ssh-2.0.11/lib/net/ssh/connection/session.rb:109:in `close'
/usr/lib/ruby/gems/1.8/gems/net-scp-1.0.2/lib/net/scp.rb:204:in `start'
/home/myself/work/server.rb:458:in `transfer_file'
你能指出这里可能有什么问题吗?在这个阶段,我的 Ruby 经验非常有限。
【问题讨论】:
-
也许只是调用 scp 命令?
-
@folder 是如何定义的?并请包含对 transfer_file 方法的示例调用
-
经过一番努力,我们设法将问题缩小到环境配置问题。上面的代码是正确的,很抱歉给它带来麻烦。对于那些感兴趣的人,“另一端”存在一些目录访问权限问题。