Class: Remi::Loader::SftpFile

Inherits:
Remi::Loader show all
Defined in:
lib/remi/data_subjects/sftp_file.rb

Overview

SFTP file loader

Examples:

class MyJob < Remi::Job
  target :my_target do
    encoder Remi::Encoder::CsvFile.new(
      csv_options: { col_sep: '|' }
    )
    loader Remi::Loader::SftpFile.new(
      credentials: { },
      remote_path: 'some_test.csv'
    )
    loader Remi::Loader::SftpFile.new(
      credentials: { },
      remote_path: 'some_other_test.csv'
    )
  end
end

my_df = Daru::DataFrame.new({ a: 1.upto(5).to_a, b: 6.upto(10) })
job = MyJob.new
job.my_target.df = my_df
job.my_target.load

Instance Attribute Summary collapse

Attributes inherited from Remi::Loader

#context, #logger

Instance Method Summary collapse

Methods inherited from Remi::Loader

#autoload, #fields

Constructor Details

#initialize(*args, **kargs, &block) ⇒ SftpFile

Returns a new instance of SftpFile.

Parameters:

  • remote_path (String, Pathname)

    Full path to the file to be created on the target filesystem



148
149
150
151
# File 'lib/remi/data_subjects/sftp_file.rb', line 148

def initialize(*args, **kargs, &block)
  super
  init_sftp_loader(*args, **kargs, &block)
end

Instance Attribute Details

#remote_pathObject (readonly)

Returns the value of attribute remote_path.



153
154
155
# File 'lib/remi/data_subjects/sftp_file.rb', line 153

def remote_path
  @remote_path
end

Instance Method Details

#load(data) ⇒ true

Copies data to the SFTP Server

Parameters:

  • data (Object)

    The path to the file in the temporary work location

Returns:

  • (true)

    On success



158
159
160
161
162
163
164
165
# File 'lib/remi/data_subjects/sftp_file.rb', line 158

def load(data)
  logger.info "Uploading #{data} to #{@credentials[:username]}@#{@credentials[:host]}: #{@remote_path}"
  connection do |sftp|
    retry_upload { sftp.upload! data, @remote_path }
  end

  true
end