Class: BackupClient::Components::Ftp::Commands::FileUpload

Inherits:
Object
  • Object
show all
Includes:
Helpers::FtpHelper, Helpers::LogHelper
Defined in:
lib/backup_client/components/ftp/commands/file_upload.rb

Instance Method Summary collapse

Methods included from Helpers::FtpHelper

#ftp_chdir, #ftp_dir_exists?, #ftp_mkdir, #ftp_mkdir_p, #root_chdir, #to_unix_path, #upload_dir_ftp, #upload_file_ftp

Methods included from Helpers::LogHelper

#log

Constructor Details

#initialize(ftp_client, local_file_path, remote_folder_path) ⇒ FileUpload

Returns a new instance of FileUpload.



11
12
13
14
15
# File 'lib/backup_client/components/ftp/commands/file_upload.rb', line 11

def initialize(ftp_client, local_file_path, remote_folder_path)
  @ftp_client         = ftp_client
  @local_file_path    = local_file_path
  @remote_folder_path = remote_folder_path
end

Instance Method Details

#callObject



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/backup_client/components/ftp/commands/file_upload.rb', line 17

def call
  remote_file_path = [remote_folder_path, to_unix_path(local_file_path)].join("/").gsub("//", "/")

  File.open(local_file_path, "rb") do |file|
    ftp_client.putbinaryfile(file, remote_file_path)
  end

  log "Uploaded file #{local_file_path} → #{remote_file_path}"
rescue StandardError => error
  log "Unexpected file upload error. #{local_file_path} → #{remote_file_path}, error: #{error.to_s}"
end