Keep Remote Directory Up-to-date

后端 未结 17 1713
一向
一向 2021-01-30 06:39

I absolutely love the Keep Remote Directory Up-to-date feature in Winscp. Unfortunately, I can\'t find anything as simple to use in OS X or Linux. I know the same thing can

17条回答
  •  鱼传尺愫
    2021-01-30 07:35

    I'm using this little Ruby-Script:

    #!/usr/bin/env ruby
    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    # Rsyncs 2Folders
    #
    # watchAndSync by Mike Mitterer, 2014 
    # with credit to Brett Terpstra 
    # and Carlo Zottmann 
    # Found link on: http://brettterpstra.com/2011/03/07/watch-for-file-changes-and-refresh-your-browser-automatically/
    #
    
    trap("SIGINT") { exit }
    
    if ARGV.length < 2
      puts "Usage: #{$0} watch_folder sync_folder"
      puts "Example: #{$0} web keepInSync"
      exit
    end
    
    dev_extension = 'dev'
    filetypes = ['css','html','htm','less','js', 'dart']
    
    watch_folder = ARGV[0]
    sync_folder = ARGV[1]
    
    puts "Watching #{watch_folder} and subfolders for changes in project files..."
    puts "Syncing with #{sync_folder}..."
    
    while true do
      files = []
      filetypes.each {|type|
        files += Dir.glob( File.join( watch_folder, "**", "*.#{type}" ) )
      }
      new_hash = files.collect {|f| [ f, File.stat(f).mtime.to_i ] }
      hash ||= new_hash
      diff_hash = new_hash - hash
    
      unless diff_hash.empty?
        hash = new_hash
    
        diff_hash.each do |df|
          puts "Detected change in #{df[0]}, syncing..."
          system("rsync -avzh #{watch_folder} #{sync_folder}")
        end
      end
    
      sleep 1
    end
    

    Adapt it for your needs!

提交回复
热议问题