【问题标题】:Ruby code has syntax error, unexpected keyword_end, expecting end-of-inputRuby 代码有语法错误、意外的keyword_end、期望输入结束
【发布时间】:2016-10-28 01:54:27
【问题描述】:

当我运行下面的 ruby​​ sftp 文件同步代码时,我得到:

box_lin.ru:46:语法错误,意外的keyword_end,预期输入结束

我在不同的地方添加了end,找不到引号或括号的语法问题。非常感谢您的帮助!

 require 'net/ssh'
 require 'net/sftp'
 require 'dir'

 local_path = '/Users/awesome/Development/box'
 remote_path = '/home/awesome/box'
 file_perm = 0644
 dir_perm = 0755

 puts 'Connecting to box...'
 Net::SSH.start('server', 'username', 'password') do |ssh|
   ssh.sftp.connect do |sftp|
 puts 'Checking for files which need updating'
 Find.find(local_path) do |file|
     next if File.stat(file).directory?
     local_file = "#{dir}/#{file}"
     remote_file = remote_path + local_file.sub(local_path, '')

     begin
     remote_dir = File.dirname(remote_file)
     sftp.stat(remote_dir)
 rescue Net::SFTP::Operations::StatusException => e 
   raise unless e.code == 2

   sftp.mkdir(remote_dir, :permissions => dir_perm)
 end

 begin
   rstat = sftp.stat(remote_file)
 rescue Net::SFTP::Operations::StatusException => e
   raise unless e.code == 2
   sftp.put_file(local_file, remote_file)
   sftp.setstat(remote_file, :permissions => file_perm)
   next
 end

 if File.stat(local_file).mtime > Time.at(rstat.mtime)
   puts "Copying #{local_file} to #{remote_file}"
   sftp.put_file(local_file, remote_file)
  end
 end
end

   puts 'Disconnecting from box...'
  end
 end

   puts ' synch complete! '

【问题讨论】:

    标签: ruby syntax ssh sftp


    【解决方案1】:

    在这一行:

    puts ‘Disconnecting from box...'
    

    你有一个勾号而不是引号。

    您还应该将其放入code review 以使其更干净。

     

    【讨论】:

    • 大眼睛!谢谢,现在归结为一个错误:box_lin.ru:46: syntax error, unexpected keyword_end, expecting end-of-input 你看到什么导致这个吗?将尝试代码审查。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多