Module: EasyDownloader::Ftp
- Included in:
- AbstractLoader
- Defined in:
- lib/easy_downloader/ftp.rb
Instance Method Summary collapse
- #change_remote_dir(ftp) ⇒ Object
- #ftp_download(options) ⇒ Object
- #ftp_password_option(password) ⇒ Object
- #ftp_upload(options) ⇒ Object
- #open_ftp(&block) ⇒ Object
- #remote_files_list(options) ⇒ Object
Instance Method Details
#change_remote_dir(ftp) ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/easy_downloader/ftp.rb', line 54 def change_remote_dir(ftp) if .remote_path.present? begin ftp.chdir(.remote_path) rescue InvalidRemoteDirectory end end end |
#ftp_download(options) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/easy_downloader/ftp.rb', line 4 def ftp_download() open_ftp do |ftp| change_remote_dir(ftp) files = ftp.nlst.select {|file_name| .remote_pattern == '*' || file_name =~ Regexp.new(.remote_pattern) } total = files.size .result.found(files.size, files) files.each do |path| .result.starting_path(path) ftp.get(path, "#{.local_path}#{path}") .load_count = .load_count + 1 .result.finished_path(path) .result.files_loaded << "#{.local_path}#{path}" end end end |
#ftp_password_option(password) ⇒ Object
63 64 65 |
# File 'lib/easy_downloader/ftp.rb', line 63 def ftp_password_option(password) password ? password : nil end |
#ftp_upload(options) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/easy_downloader/ftp.rb', line 23 def ftp_upload() open_ftp do |ftp| change_remote_dir(ftp) files = local_files_list() .result.found(files.size, files) files.each do |path| .result.starting_path(path) if .remote_file ftp.put(path, .remote_file) .result.files_loaded << .remote_file else ftp.put(path) .result.files_loaded << File.basename(path) end .load_count= .load_count + 1 .result.finished_path(path) end end end |
#open_ftp(&block) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/easy_downloader/ftp.rb', line 46 def open_ftp(&block) Net::FTP.open(.host, .user, ftp_password_option(.password)) do |ftp| yield(ftp) end end |
#remote_files_list(options) ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/easy_downloader/ftp.rb', line 68 def remote_files_list() if .remote_file [.remote_file] else Dir[.remote_path, .remote_pattern] end end |