2014-05-21 2 views
-1

Все работает до строки 32, где я пытаюсь найти, какие файлы и каталоги необходимо загрузить на резервный сервер. Можете ли вы помочь мне синхронизировать файлы с local_path на remote_path? Спасибо за помощь!ruby ​​filesync gem, uninitialized constant Find (NameError)

Когда я запускаю это я получаю:

box.ru:32:in `block (2 levels) in <main>': uninitialized constant Find (NameError) 
from /Library/Ruby/Gems/2.0.0/gems/net-sftp-2.1.2/lib/net/sftp/session.rb:769:in `call' 
from /Library/Ruby/Gems/2.0.0/gems/net-sftp-2.1.2/lib/net/sftp/session.rb:769:in `connect' 
from newbox.ru:28:in `block in <main>' 
from /Library/Ruby/Gems/2.0.0/gems/net-ssh-2.9.1/lib/net/ssh.rb:210:in `start' 
from newbox.ru:25:in `<main>' 
#!/usr/bin/env ruby 
require 'rubygems' 
require 'net/ssh' 
require 'net/sftp' 
require 'highline/import' 


host = 'server' 
local_path = '/Users/awesome1/Development/box' 
remote_path = '/home/awesome2/box' 

def sanitize_string(string_name) 
string_name.gsub(/[^\w\.\-]/,"_") 
end 


puts "box username:" 
user0 = gets.chomp 
user = sanitize_string(user0) 

pass0 = ask("Enter password for #{user}: ") { |q| q.echo = false } 
pass = sanitize_string(pass0) 

puts 'connecting to box...' 
Net::SSH.start(host, user, :password => pass) do|ssh| 
result = ssh.exec!("cd #{remote_path} && ls") 
puts result 
    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, :mode => 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}" 
    ssh.sftp.upload(local_file, remote_file) 
    end 
end 
end 
end 

ответ

1

Ваш box.ru пропускает require 'find' строку:

require 'find' 

puts 'connecting to box...' 
Net::SSH.start(host, user, :password => pass) do|ssh| 
result = ssh.exec!("cd #{remote_path} && ls") 
puts result 
    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, '') 
# ... 
Смежные вопросы