Class: ETL::Processor::FtpUploaderProcessor

Inherits:
Processor show all
Defined in:
lib/etl/processor/ftp_uploader_processor.rb

Overview

Custom processor to download files via FTP

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(control, configuration) ⇒ FtpUploaderProcessor

configuration options include:

  • host - hostname or IP address of FTP server (required)

  • port - port number for FTP server (default: 21)

  • remote_dir - remote path on FTP server (default: /)

  • files - list of files to download from FTP server (default: [])

  • username - username for FTP server authentication (default: anonymous)

  • password - password for FTP server authentication (default: nil)

  • local_dir - local output directory to save downloaded files (default: ”)

As an example you might write something like the following in your control process file:

pre_process :ftp_uploader, {
  :host => 'ftp.sec.gov',
  :path => 'edgar/Feed/2007/QTR2',
  :files => ['20070402.nc.tar.gz', '20070403.nc.tar.gz', '20070404.nc.tar.gz', 
             '20070405.nc.tar.gz', '20070406.nc.tar.gz'],
  :local_dir => '/data/sec/2007/04',
}

The above example will anonymously download via FTP the first week’s worth of SEC filing feed data from the second quarter of 2007 and download the files to the local directory /data/sec/2007/04.



33
34
35
36
37
38
39
40
41
# File 'lib/etl/processor/ftp_uploader_processor.rb', line 33

def initialize(control, configuration)
  @host = configuration[:host]
  @port = configuration[:port] || 21
  @remote_dir = configuration[:remote_dir] || '/'
  @files = configuration[:files] || []
  @username = configuration[:username] || 'anonymous'
  @password = configuration[:password]
  @local_dir = configuration[:local_dir] || ''
end

Instance Attribute Details

#filesObject (readonly)

Returns the value of attribute files.



10
11
12
# File 'lib/etl/processor/ftp_uploader_processor.rb', line 10

def files
  @files
end

#hostObject (readonly)

Returns the value of attribute host.



7
8
9
# File 'lib/etl/processor/ftp_uploader_processor.rb', line 7

def host
  @host
end

#local_dirObject (readonly)

Returns the value of attribute local_dir.



12
13
14
# File 'lib/etl/processor/ftp_uploader_processor.rb', line 12

def local_dir
  @local_dir
end

#portObject (readonly)

Returns the value of attribute port.



8
9
10
# File 'lib/etl/processor/ftp_uploader_processor.rb', line 8

def port
  @port
end

#remote_dirObject (readonly)

Returns the value of attribute remote_dir.



9
10
11
# File 'lib/etl/processor/ftp_uploader_processor.rb', line 9

def remote_dir
  @remote_dir
end

#usernameObject (readonly)

Returns the value of attribute username.



11
12
13
# File 'lib/etl/processor/ftp_uploader_processor.rb', line 11

def username
  @username
end

Instance Method Details

#processObject



43
44
45
46
47
48
49
50
51
# File 'lib/etl/processor/ftp_uploader_processor.rb', line 43

def process
  Net::FTP.open(@host) do |conn|
    conn.connect(@host, @port)
    conn.(@username, @password)
    @files.each do |f|
      conn.putbinaryfile(local_file(f), remote_file(f))
    end
  end
end