Class: Stockboy::Providers::FTP::SFTPAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/stockboy/providers/ftp/sftp_adapter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(provider) ⇒ SFTPAdapter

Returns a new instance of SFTPAdapter.



7
8
9
10
# File 'lib/stockboy/providers/ftp/sftp_adapter.rb', line 7

def initialize(provider)
  @provider = provider
  @file_dir = "."
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



5
6
7
# File 'lib/stockboy/providers/ftp/sftp_adapter.rb', line 5

def client
  @client
end

Instance Method Details

#chdir(directory) ⇒ Object



21
22
23
# File 'lib/stockboy/providers/ftp/sftp_adapter.rb', line 21

def chdir(directory)
  @file_dir = ::File.join(directory, '')
end

#delete(file_name) ⇒ Object



29
30
31
# File 'lib/stockboy/providers/ftp/sftp_adapter.rb', line 29

def delete(file_name)
  client.remove!(full_path(file_name))
end

#download(file_name) ⇒ Object



33
34
35
# File 'lib/stockboy/providers/ftp/sftp_adapter.rb', line 33

def download(file_name)
  client.download!(full_path(file_name))
end

#list_filesObject



25
26
27
# File 'lib/stockboy/providers/ftp/sftp_adapter.rb', line 25

def list_files
  client.dir.entries(@file_dir).map(&:name).sort
end

#modification_time(file_name) ⇒ Object



37
38
39
# File 'lib/stockboy/providers/ftp/sftp_adapter.rb', line 37

def modification_time(file_name)
  stat(file_name).mtime
end

#openObject



12
13
14
15
16
17
18
19
# File 'lib/stockboy/providers/ftp/sftp_adapter.rb', line 12

def open
  result = nil
  Net::SFTP.start(@provider.host, @provider.username, password: @provider.password) do |sftp|
    @client = sftp
    result = yield self
  end
  result
end

#size(file_name) ⇒ Object



41
42
43
# File 'lib/stockboy/providers/ftp/sftp_adapter.rb', line 41

def size(file_name)
  stat(file_name).size
end