Class: BBMB::Util::FtpMission
- Inherits:
-
Object
- Object
- BBMB::Util::FtpMission
- Defined in:
- lib/bbmb/util/polling_manager.rb
Instance Attribute Summary collapse
-
#backup_dir ⇒ Object
Returns the value of attribute backup_dir.
-
#delete ⇒ Object
Returns the value of attribute delete.
-
#directory ⇒ Object
Returns the value of attribute directory.
-
#pattern ⇒ Object
Returns the value of attribute pattern.
Instance Method Summary collapse
-
#initialize(*args) ⇒ FtpMission
constructor
A new instance of FtpMission.
- #poll(&block) ⇒ Object
- #poll_file(path, &block) ⇒ Object
- #poll_remote(ftp, file) ⇒ Object
- #regexp ⇒ Object
Constructor Details
#initialize(*args) ⇒ FtpMission
Returns a new instance of FtpMission.
92 93 94 95 |
# File 'lib/bbmb/util/polling_manager.rb', line 92 def initialize(*args) super @regexp = Regexp.new('.*') end |
Instance Attribute Details
#backup_dir ⇒ Object
Returns the value of attribute backup_dir.
91 92 93 |
# File 'lib/bbmb/util/polling_manager.rb', line 91 def backup_dir @backup_dir end |
#delete ⇒ Object
Returns the value of attribute delete.
91 92 93 |
# File 'lib/bbmb/util/polling_manager.rb', line 91 def delete @delete end |
#directory ⇒ Object
Returns the value of attribute directory.
91 92 93 |
# File 'lib/bbmb/util/polling_manager.rb', line 91 def directory @directory end |
#pattern ⇒ Object
Returns the value of attribute pattern.
91 92 93 |
# File 'lib/bbmb/util/polling_manager.rb', line 91 def pattern @pattern end |
Instance Method Details
#poll(&block) ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/bbmb/util/polling_manager.rb', line 96 def poll(&block) @backup_dir ||= Dir.tmpdir FileUtils.mkdir_p(@backup_dir) @regexp = Regexp.new(@pattern || '.*') uri = URI.parse(@directory) locals = [] Net::FTP.open(uri.host) do |ftp| ftp.login uri.user, uri.password ftp.chdir uri.path ftp.nlst.each do |file| if(local = poll_remote ftp, file) locals.push local end end end locals.each do |path| poll_file path, &block end end |
#poll_file(path, &block) ⇒ Object
115 116 117 118 119 120 121 |
# File 'lib/bbmb/util/polling_manager.rb', line 115 def poll_file(path, &block) File.open(path) { |io| block.call(File.basename(path), io) } rescue StandardError => err BBMB::Util::Mail.notify_error(err) end |
#poll_remote(ftp, file) ⇒ Object
122 123 124 125 126 127 128 129 |
# File 'lib/bbmb/util/polling_manager.rb', line 122 def poll_remote(ftp, file) if(@regexp.match file) local = File.join(@backup_dir, file) ftp.get file, local ftp.delete file if @delete local end end |
#regexp ⇒ Object
130 131 |
# File 'lib/bbmb/util/polling_manager.rb', line 130 def regexp end |