Class: WinRM::FS::FileManager

Inherits:
Object
  • Object
show all
Defined in:
lib/evil-winrm.rb

Instance Method Summary collapse

Instance Method Details

#download(remote_path, local_path, chunk_size = 1024 * 1024, first = true, size: -1)) ⇒ Object


85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/evil-winrm.rb', line 85

def download(remote_path, local_path, chunk_size = 1024 * 1024, first = true, size: -1)
    @logger.debug("downloading: #{remote_path} -> #{local_path} #{chunk_size}")
    index = 0
    output = _output_from_file(remote_path, chunk_size, index)
    return download_dir(remote_path, local_path, chunk_size, first) if output.exitcode == 2

    return false if output.exitcode >= 1

    File.open(local_path, 'wb') do |fd|
        out = _write_file(fd, output)
        index += out.length
        until out.empty?
            if size != -1
                yield index, size
            end
            output = _output_from_file(remote_path, chunk_size, index)
            return false if output.exitcode >= 1

            out = _write_file(fd, output)
            index += out.length
        end
    end
end