代码之家  ›  专栏  ›  技术社区  ›  Baz

SCP未成功完成(1)尝试使用ruby从windows上载到Ubuntu时出错

  •  1
  • Baz  · 技术社区  · 12 年前

    我的代码

    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初学者,所以如果你能给我任何关于如何进一步调试这段代码的帮助,我将不胜感激。

    谢谢

    2 回复  |  直到 12 年前
        1
  •  1
  •   Paul Verschoor    12 年前

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

    尝试在不提供完整路径的情况下保存它,这样它就可以在Ubuntu服务器上的用户主目录中结束。如果这能奏效,那么您的问题与服务器上的用户权限有关。

        2
  •  1
  •   Bdebeez    12 年前

    如果这对其他人有帮助,我在尝试将文件上载到一个尚不存在的路径时遇到了与此完全相同的错误。来自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。

    推荐文章