Class: Dandelion::Adapter::FTP

Inherits:
Base
  • Object
show all
Includes:
Utils
Defined in:
lib/dandelion/adapter/ftp.rb

Direct Known Subclasses

FTPS

Instance Method Summary collapse

Methods included from Utils

#temp

Methods inherited from Base

adapter, create_adapter, requires_gems

Constructor Details

#initialize(config) ⇒ FTP

Returns a new instance of FTP.



10
11
12
13
14
15
16
17
18
# File 'lib/dandelion/adapter/ftp.rb', line 10

def initialize(config)
  require 'net/ftp'

  @config = config
  @config.defaults(port: Net::FTP::FTP_PORT)
  @config[:passive] = to_b(@config[:passive])

  @ftp = ftp_client
end

Instance Method Details

#delete(file) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/dandelion/adapter/ftp.rb', line 40

def delete(file)
  begin
    @ftp.delete(path(file))
    cleanup(File.dirname(path(file)))
  rescue Net::FTPPermError => e
  end
end

#read(file) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/dandelion/adapter/ftp.rb', line 20

def read(file)
  begin
    @ftp.get(path(file), nil)
  rescue Net::FTPPermError => e
    nil
  end
end

#to_sObject



48
49
50
# File 'lib/dandelion/adapter/ftp.rb', line 48

def to_s
  "ftp://#{@config['username']}@#{@config['host']}/#{@config['path']}"
end

#write(file, data) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/dandelion/adapter/ftp.rb', line 28

def write(file, data)
  temp(file, data) do |temp|
    begin
      @ftp.put(temp, path(file))
    rescue Net::FTPPermError => e
      raise e unless e.to_s =~ /550|553/
      mkdir_p(File.dirname(path(file)))
      @ftp.put(temp, path(file))
    end
  end
end