Class: FileTransfer::Sftp

Inherits:
Generic
  • Object
show all
Defined in:
lib/file_transfer/sftp.rb

Instance Attribute Summary

Attributes inherited from Generic

#host, #password, #port, #timeout_seconds, #username

Instance Method Summary collapse

Methods inherited from Generic

#exist?, #move, #to_s

Constructor Details

#initialize(options = {}) ⇒ Sftp

Returns a new instance of Sftp.



5
6
7
8
# File 'lib/file_transfer/sftp.rb', line 5

def initialize(options = {})
  options[:port] ||= 22
  super(options)
end

Instance Method Details

#closeObject



45
46
47
# File 'lib/file_transfer/sftp.rb', line 45

def close
 # do nothing
end

#download(from_path, to_path) ⇒ Object



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

def download(from_path, to_path)
  connect if closed?
  timeout(timeout_seconds) do
    @sftp.download! from_path, to_path
  end
end

#list(path) ⇒ Object



24
25
26
27
28
29
# File 'lib/file_transfer/sftp.rb', line 24

def list(path)
  connect if closed?
  timeout(60) do
    @sftp.dir.entries path
  end
end

#remove(path) ⇒ Object



31
32
33
34
35
36
# File 'lib/file_transfer/sftp.rb', line 31

def remove(path)
  connect if closed?
  timeout(60) do
    @sftp.remove! path
  end
end

#rename(from_path, to_path) ⇒ Object



38
39
40
41
42
43
# File 'lib/file_transfer/sftp.rb', line 38

def rename(from_path, to_path)
  connect if closed?
  timeout(60) do
    @sftp.rename! from_path, to_path
  end
end

#upload(from_path, to_path) ⇒ Object



17
18
19
20
21
22
# File 'lib/file_transfer/sftp.rb', line 17

def upload(from_path, to_path)
  connect if closed?
  timeout(timeout_seconds) do
    @sftp.upload! from_path, to_path
  end
end