Class: SSHKit::Backend::Netssh::SftpTransfer

Inherits:
Object
  • Object
show all
Defined in:
lib/sshkit/backends/netssh/sftp_transfer.rb

Instance Method Summary collapse

Constructor Details

#initialize(ssh, summarizer) ⇒ SftpTransfer

Returns a new instance of SftpTransfer.



7
8
9
10
# File 'lib/sshkit/backends/netssh/sftp_transfer.rb', line 7

def initialize(ssh, summarizer)
  @ssh = ssh
  @summarizer = summarizer
end

Instance Method Details

#download!(remote, local, options) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/sshkit/backends/netssh/sftp_transfer.rb', line 20

def download!(remote, local, options)
  options = { progress: self }.merge(options || {})
  destination = local ? local : StringIO.new.tap { |io| io.set_encoding('BINARY') }

  ssh.sftp.connect!
  ssh.sftp.download!(remote, destination, options)
  local ? true : destination.string
ensure
  ssh.sftp.close_channel
end

#on_get(download, entry, offset, data) ⇒ Object



31
32
33
34
# File 'lib/sshkit/backends/netssh/sftp_transfer.rb', line 31

def on_get(download, entry, offset, data)
  entry.size ||= download.sftp.file.open(entry.remote) { |file| file.stat.size }
  summarizer.call(nil, entry.remote, offset + data.bytesize, entry.size)
end

#on_put(_upload, file, offset, data) ⇒ Object



36
37
38
# File 'lib/sshkit/backends/netssh/sftp_transfer.rb', line 36

def on_put(_upload, file, offset, data)
  summarizer.call(nil, file.local, offset + data.bytesize, file.size)
end

#upload!(local, remote, options) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/sshkit/backends/netssh/sftp_transfer.rb', line 12

def upload!(local, remote, options)
  options = { progress: self }.merge(options || {})
  ssh.sftp.connect!
  ssh.sftp.upload!(local, remote, options)
ensure
  ssh.sftp.close_channel
end