Ruby代码有语法错误,意外的keyword_end,期望输入结束

时间:2014-05-17 22:30:26

标签: ruby syntax ssh sftp

当我运行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! '

1 个答案:

答案 0 :(得分:0)

在这一行:

puts ‘Disconnecting from box...'

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

您还应该将其放入code review以使其更清晰。