Class: SSHKit::Backend::Netssh::SftpTransfer
- Inherits:
-
Object
- Object
- SSHKit::Backend::Netssh::SftpTransfer
- Defined in:
- lib/sshkit/backends/netssh/sftp_transfer.rb
Instance Method Summary collapse
- #download!(remote, local, options) ⇒ Object
-
#initialize(ssh, summarizer) ⇒ SftpTransfer
constructor
A new instance of SftpTransfer.
- #on_get(download, entry, offset, data) ⇒ Object
- #on_put(_upload, file, offset, data) ⇒ Object
- #upload!(local, remote, options) ⇒ Object
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, ) = { progress: self }.merge( || {}) destination = local ? local : StringIO.new.tap { |io| io.set_encoding('BINARY') } ssh.sftp.connect! ssh.sftp.download!(remote, destination, ) 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, ) = { progress: self }.merge( || {}) ssh.sftp.connect! ssh.sftp.upload!(local, remote, ) ensure ssh.sftp.close_channel end |