Class: Feed::TransmitFtps
- Inherits:
-
Object
- Object
- Feed::TransmitFtps
- Defined in:
- app/services/feed/transmit_ftps.rb
Defined Under Namespace
Classes: Result
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ TransmitFtps
constructor
A new instance of TransmitFtps.
- #process(upload_or_file_path) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ TransmitFtps
Returns a new instance of TransmitFtps.
10 11 12 13 14 15 16 17 18 |
# File 'app/services/feed/transmit_ftps.rb', line 10 def initialize(={}) @logger = .delete(:logger) @hostname = [:hostname] @ftp_passive = [:ftp_passive] @username = .delete(:username) @password = .delete(:password) @remote_directory = [:remote_directory] @options = end |
Instance Method Details
#process(upload_or_file_path) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/services/feed/transmit_ftps.rb', line 20 def process(upload_or_file_path) result_hsh = {} begin local_file_path = nil file_name = nil if upload_or_file_path.is_a?(Upload) local_file_path = upload_or_file_path..path file_name = upload_or_file_path. else local_file_path = upload_or_file_path file_name = File.basename(local_file_path) end result_hsh[:file_name] = file_name result_hsh[:transmitted] = false #Default result_hsh[:status] = :error # Default DoubleBagFTPS.open(@hostname,@username, @password, nil, DoubleBagFTPS::EXPLICIT) do |ftp| ftp.passive = @ftp_passive @logger.info "Starting Transmission of #{file_name} to #{@hostname}/#{@remote_directory}" if @remote_directory.present? @logger.info "Changing to remote directory #{@remote_directory}" ftp.chdir(@remote_directory) end @logger.info "Transfer started" ftp.puttextfile(local_file_path, file_name) @logger.info "Transfer of #{local_file_path} complete" ftp.quit result_hsh[:transmitted] = true result_hsh[:status] = :ok end rescue StandardError => exc msg = "Failed to transmit. #{@options.inspect} - #{exc.}" result_hsh[:message] = msg ErrorReporting.error(exc, msg) end Result.new(**result_hsh) end |