Class: ScpUploader

Inherits:
Object
  • Object
show all
Defined in:
lib/captured/uploaders/scp_uploader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ ScpUploader

Returns a new instance of ScpUploader.



4
5
6
# File 'lib/captured/uploaders/scp_uploader.rb', line 4

def initialize(config = {})
  @config = config
end

Instance Attribute Details

#urlObject

Returns the value of attribute url.



2
3
4
# File 'lib/captured/uploaders/scp_uploader.rb', line 2

def url
  @url
end

Instance Method Details

#gen_remote_name(file) ⇒ Object



8
9
10
# File 'lib/captured/uploaders/scp_uploader.rb', line 8

def gen_remote_name(file)
  Digest::MD5.hexdigest(file+Time.now.to_i.to_s) +  File.extname(file)
end

#upload(file) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/captured/uploaders/scp_uploader.rb', line 12

def upload(file)
  puts "Uploading #{file}"
  # TODO: This needs to be called from file upload
  # and this calss needs to be completed
  # maybe some tests
  require 'net/scp'
  require 'etc'
  settings = @config['upload']
  remote_name = gen_remote_name(file)
  puts Net::SCP.upload!(settings['host'],
                   settings['user'] || Etc.getlogin,
                   file,
                   settings['path']+remote_name,
                   :password => settings['password'])

  @url = "#{@config['upload']['url']}#{remote_name}"
  @url
end