Ruby代码有语法错误,意外的关键字\u end,应为输入结尾

Ruby代码有语法错误,意外的关键字\u end,应为输入结尾,ruby,syntax,ssh,sftp,Ruby,Syntax,Ssh,Sftp,当我运行下面的ruby sftp文件同步代码时,我得到: box_lin.ru:46:语法错误,意外的关键字_end,应为输入结尾 我在不同的地方添加了end,但找不到引号或括号的语法问题。非常感谢您的帮助 require 'net/ssh' require 'net/sftp' require 'dir' local_path = '/Users/awesome/Development/box' remote_path = '/home/awesome/box' file_per

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

box_lin.ru:46:语法错误,意外的关键字_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! '
在这方面:

puts ‘Disconnecting from box...'
你有一个勾号而不是引号

你也应该把它放进一个盒子里,让它更干净


大眼睛!谢谢,现在只剩下一个错误:box_lin.ru:46:语法错误,意外的关键字_end,预期输入结束。您看到导致此错误的原因了吗?将尝试代码复查。