Class: Remi::Extractor::SftpFile
- Inherits:
-
FileSystem
- Object
- FileSystem
- Remi::Extractor::SftpFile
- Defined in:
- lib/remi/extractor/sftp_file.rb
Constant Summary collapse
- N_RETRY =
3
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Attributes inherited from FileSystem
#group_by, #local_path, #logger, #most_recent_by, #most_recent_only, #pattern, #remote_path
Instance Method Summary collapse
-
#all_entries ⇒ Object
Public: Returns an array of all FileSystemEntry instances that are in the remote_path.
- #all_entries! ⇒ Object
-
#extract ⇒ Object
Public: Called to extract files from the source filesystem.
-
#initialize(*args, **kargs) ⇒ SftpFile
constructor
A new instance of SftpFile.
Methods inherited from FileSystem
#entries, #matching_entries, #most_recent_matching_entry, #most_recent_matching_entry_in_group
Constructor Details
#initialize(*args, **kargs) ⇒ SftpFile
Returns a new instance of SftpFile.
8 9 10 11 |
# File 'lib/remi/extractor/sftp_file.rb', line 8 def initialize(*args, **kargs) super init_sftp_file(*args, **kargs) end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
13 14 15 |
# File 'lib/remi/extractor/sftp_file.rb', line 13 def host @host end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
15 16 17 |
# File 'lib/remi/extractor/sftp_file.rb', line 15 def password @password end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
16 17 18 |
# File 'lib/remi/extractor/sftp_file.rb', line 16 def port @port end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
14 15 16 |
# File 'lib/remi/extractor/sftp_file.rb', line 14 def username @username end |
Instance Method Details
#all_entries ⇒ Object
Public: Returns an array of all FileSystemEntry instances that are in the remote_path.
33 34 35 |
# File 'lib/remi/extractor/sftp_file.rb', line 33 def all_entries @all_entries ||= all_entries! end |
#all_entries! ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/remi/extractor/sftp_file.rb', line 37 def all_entries! sftp_entries = connection { |sftp| sftp.dir.entries(@remote_path) } sftp_entries.map do |entry| # Early versions of the protocol don't support create time, fake it with modified time? FileSystemEntry.new( pathname: File.join(@remote_path, entry.name), create_time: entry.attributes.respond_to?(:createtime) ? entry.attributes.createtime : entry.attributes.mtime, modified_time: entry.attributes.mtime ) end end |
#extract ⇒ Object
Public: Called to extract files from the source filesystem.
Returns an array with containing the paths to all files extracted.
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/remi/extractor/sftp_file.rb', line 21 def extract connection do |sftp| entries.map do |entry| local_file = File.join(@local_path, entry.name) @logger.info "Downloading #{entry.name} to #{local_file}" retry_download { sftp.download!(File.join(@remote_path, entry.name), local_file) } local_file end end end |