Class: XmlConv::Util::FtpMission
- Defined in:
- lib/xmlconv/util/polling_manager.rb
Instance Attribute Summary collapse
-
#glob_pattern ⇒ Object
Returns the value of attribute glob_pattern.
-
#origin ⇒ Object
Returns the value of attribute origin.
Attributes inherited from Mission
#arguments, #backup_dir, #debug_recipients, #destination, #error_recipients, #filter, #partner, #postprocs, #reader, #tmp_destination, #writer
Instance Method Summary collapse
Methods inherited from Mission
#create_transaction, #filtered_transaction
Instance Attribute Details
#glob_pattern ⇒ Object
Returns the value of attribute glob_pattern.
103 104 105 |
# File 'lib/xmlconv/util/polling_manager.rb', line 103 def glob_pattern @glob_pattern end |
#origin ⇒ Object
Returns the value of attribute origin.
103 104 105 |
# File 'lib/xmlconv/util/polling_manager.rb', line 103 def origin @origin end |
Instance Method Details
#file_names(ftp) ⇒ Object
104 105 106 107 |
# File 'lib/xmlconv/util/polling_manager.rb', line 104 def file_names(ftp) pattern = @glob_pattern || '*' ftp.nlst.select do |name| File.fnmatch pattern, name end end |
#poll(&block) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/xmlconv/util/polling_manager.rb', line 108 def poll(&block) uri = URI.parse(@origin) origin_dir = "ftp://#{uri.user}@#{uri.host}#{uri.path}" require 'net/ftp' Net::FTP.open(uri.host, uri.user, uri.password) do |ftp| ftp.chdir uri.path file_names(ftp).each do |name| begin origin = File.join origin_dir, name FileUtils.mkdir_p(@backup_dir) target = File.join(@backup_dir, name) ftp.gettextfile name, target filtered_transaction File.read(target), origin do |trans| block.call trans end rescue Exception => e puts e puts e.backtrace ensure ftp.delete name end end end end |