【问题标题】:SCP did not finish successfully (1) Error when Trying to Upload from windows to Ubuntu using rubySCP 未成功完成 (1) 尝试使用 ruby​​ 从 Windows 上传到 Ubuntu 时出错
【发布时间】:2014-05-04 17:00:29
【问题描述】:

我的代码

IMAGE_DIR = 'D:\File_Server\Nisa_Costcutter\Master Nisa CC Logos'

require 'net/ssh'
require 'net/scp'

def scopy_file(file)
  puts "Transferring #{file.path}"
  Net::SCP.upload!('192.168.254.5', 
                   'passenger', 
                    file, 
                    '/var/www/pinpointlms.co.uk/shared/logos', 
                    :ssh => {password: '*****'})
end

puts "Starting Upload"

Dir.foreach(IMAGE_DIR) do |name|
  if name.length > 4 && name[-4..-1].upcase == '.BMP'

    filename=name.strip()
    file = File.new(File.join(IMAGE_DIR, filename))

    if (Time.now - file.mtime) > 86400
        scopy_file(file) 
    end


  end


end
puts "End of Transfer"

我正在尝试使用 Ruby 将一些文件从 Windows 机器复制到 Ubuntu 机器,但我得到以下输出:

Starting Upload
Transferring D:\File_Server\Nisa_Costcutter\Master Nisa CC Logos/Z2579.BMP
C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-scp-1.1.2/lib/net/scp.rb:359:in `block (3 levels) in start_command': SCP did not finish successfully (1) 
(Net::SCP::Error) from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-ssh-2.8.0/lib/net/ssh/connection/channel.rb:591:in `call' 
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-ssh-2.8.0/lib/net/ssh/connection/channel.rb:591:in `do_close'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:586:in `channel_close'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:465:in `dispatch_incoming_packets'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:221:in `preprocess'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:205:in `process'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:169:in `block in loop'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:169:in `loop'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:169:in `loop'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:118:in `close'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-scp-1.1.2/lib/net/scp.rb:205:in `ensure in start'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-scp-1.1.2/lib/net/scp.rb:205:in `start'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-scp-1.1.2/lib/net/scp.rb:221:in `upload!'
    from C:/Users/administrator.GASKANDHAWLEY/Desktop/copy_images2.rb:8:in `scopy_file'
    from C:/Users/administrator.GASKANDHAWLEY/Desktop/copy_images2.rb:24:in`block in <main>'
    from C:/Users/administrator.GASKANDHAWLEY/Desktop/copy_images2.rb:17:in`foreach'
    from C:/Users/administrator.GASKANDHAWLEY/Desktop/copy_images2.rb:17:in

`'

我是一名 ruby​​ 初学者,因此非常感谢您对如何进一步调试此代码提供的任何帮助。

谢谢

【问题讨论】:

    标签: ruby windows ubuntu ssh scp


    【解决方案1】:

    您可能没有用户访问权限来在您的 Ubuntu 服务器上的给定目录“/var/www/pinpointlms.co.uk/shared/logos”中上传(写入)该文件。

    尝试在不提供完整路径的情况下保存它,因此它最终位于 Ubuntu 服务器上用户的主目录中。如果这可行,那么您的问题与服务器上的用户权限有关。

    【讨论】:

      【解决方案2】:

      如果它对其他人有帮助,我在尝试将文件上传到尚不存在的路径时遇到与此完全相同的错误。来自 shell 的 scp 将允许您执行此操作,但 Net::SCP 将因此错误而失败。

      scp "my.file" "/foo/bar/"
      

      如果 /foo 存在但 /foo/bar/ 不存在,scp 将创建 /foo/bar 并将您的文件放在那里(假设权限允许您这样做)。

      但是 - 在相同的情况下 - 这将失败并出现问题中给出的错误

      scp.upload!(my_file, "/foo/bar/")
      

      我找到的唯一解决方案是首先在本地创建您想要的路径,然后使用 :recursive 选项上传,如下所示:

      scp.upload!("bar/", "/foo" :recursive => true)
      

      其中 ./bar 包含 my_file。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-04-21
        • 1970-01-01
        • 2013-04-16
        • 1970-01-01
        • 2014-06-12
        • 2019-12-22
        • 1970-01-01
        • 2016-08-31
        相关资源
        最近更新 更多