Class: WinRM::Transport::FileTransporter
- Inherits:
-
Object
- Object
- WinRM::Transport::FileTransporter
- Includes:
- Logging
- Defined in:
- lib/winrm/transport/file_transporter.rb
Overview
Object which can upload one or more files or directories to a remote host over WinRM using PowerShell scripts and CMD commands. Note that this form of file transfer is not ideal and extremely costly on both the local and remote sides. Great pains are made to minimize round trips to the remote host and to minimize the number of PowerShell sessions being invoked which can be 2 orders of magnitude more expensive than vanilla CMD commands.
This object is supported by either a ‘WinRM::WinRMWebService` or `CommandExecutor` instance as it depends on the `#run_cmd` and `#run_powershell_script` API contracts.
An optional logger can be supplied, assuming it can respond to the ‘#debug` and `#debug?` messages.
Instance Method Summary collapse
-
#initialize(service, logger = nil, opts = {}) ⇒ FileTransporter
constructor
Creates a FileTransporter given a service object and optional logger.
-
#upload(locals, remote) ⇒ Hash
Uploads a collection of files and/or directories to the remote host.
Methods included from Logging
Constructor Details
#initialize(service, logger = nil, opts = {}) ⇒ FileTransporter
Creates a FileTransporter given a service object and optional logger. The service object may be a ‘WinRM::WinRMWebService` or `CommandExecutor` instance.
66 67 68 69 70 |
# File 'lib/winrm/transport/file_transporter.rb', line 66 def initialize(service, logger = nil, opts = {}) @service = service @logger = logger @id_generator = opts.fetch(:id_generator) { -> { SecureRandom.uuid } } end |
Instance Method Details
#upload(locals, remote) ⇒ Hash
Uploads a collection of files and/or directories to the remote host.
**TODO Notes:**
-
options could specify zip mode, zip options, etc.
-
maybe option to set tmpfile base dir to override $env:PATH?
-
progress yields block like net-scp progress
-
final API: def upload(locals, remote, _options = {}, &_progress)
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/winrm/transport/file_transporter.rb', line 84 def upload(locals, remote) files = nil elapsed = Benchmark.measure do files = make_files_hash(Array(locals), remote) report = check_files(files) merge_with_report!(files, report) report = stream_upload_files(files) merge_with_report!(files, report) report = decode_files(files) merge_with_report!(files, report) cleanup(files) end debug { "Uploaded #{files.keys.size} items " \ "in #{duration(elapsed.real)}" } files end |