Class: Frank::Publish::SFTP

Inherits:
Base
  • Object
show all
Defined in:
lib/frank/publish/sftp.rb

Instance Attribute Summary

Attributes inherited from Base

#hostname, #local_path, #password, #port, #remote_path, #username

Instance Method Summary collapse

Methods inherited from Base

#perform!

Constructor Details

#initialize(options, &block) ⇒ SFTP

Returns a new instance of SFTP.


10
11
12
13
14
15
# File 'lib/frank/publish/sftp.rb', line 10

def initialize(options, &block)
  super(options)
  instance_eval(&block) if block_given?

  @port ||= 22
end

Instance Method Details

#connectionObject


18
19
20
21
22
# File 'lib/frank/publish/sftp.rb', line 18

def connection
  Net::SFTP.start(hostname, username, :password => password) do |scp|
    yield scp
  end
end

#transfer!Object


24
25
26
27
28
29
30
31
32
33
# File 'lib/frank/publish/sftp.rb', line 24

def transfer!
  connection do |scp|
    old_name = ''
    scp.upload! local_path, remote_path do |ch, name|
      if old_name != name
        ok_message "Uploading #{name}", "    - "
      end
    end
  end
end