winrm-fs 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +10 -10
- data/.rspec +3 -3
- data/.rubocop.yml +9 -9
- data/.travis.yml +9 -9
- data/Gemfile +5 -5
- data/LICENSE +202 -202
- data/README.md +79 -79
- data/Rakefile +28 -28
- data/VERSION +1 -1
- data/Vagrantfile +9 -9
- data/appveyor.yml +39 -39
- data/bin/rwinrmcp +86 -86
- data/changelog.md +54 -51
- data/lib/winrm-fs.rb +28 -28
- data/lib/winrm-fs/core/file_transporter.rb +527 -527
- data/lib/winrm-fs/core/tmp_zip.rb +177 -166
- data/lib/winrm-fs/exceptions.rb +28 -28
- data/lib/winrm-fs/file_manager.rb +118 -117
- data/lib/winrm-fs/scripts/check_files.ps1.erb +49 -49
- data/lib/winrm-fs/scripts/checksum.ps1.erb +13 -13
- data/lib/winrm-fs/scripts/create_dir.ps1.erb +6 -6
- data/lib/winrm-fs/scripts/delete.ps1.erb +6 -6
- data/lib/winrm-fs/scripts/download.ps1.erb +8 -8
- data/lib/winrm-fs/scripts/exists.ps1.erb +10 -10
- data/lib/winrm-fs/scripts/extract_files.ps1.erb +52 -52
- data/lib/winrm-fs/scripts/scripts.rb +31 -31
- data/spec/config-example.yml +2 -2
- data/spec/integration/file_manager_spec.rb +224 -224
- data/spec/integration/tmp_zip_spec.rb +26 -26
- data/spec/matchers.rb +58 -58
- data/spec/spec_helper.rb +71 -71
- data/spec/unit/tmp_zip_spec.rb +79 -79
- data/winrm-fs.gemspec +37 -37
- metadata +3 -3
data/README.md
CHANGED
@@ -1,79 +1,79 @@
|
|
1
|
-
# File system operations over Windows Remote Management (WinRM) for Ruby
|
2
|
-
[![Build Status](https://travis-ci.org/WinRb/winrm-fs.svg?branch=master)](https://travis-ci.org/WinRb/winrm-fs)
|
3
|
-
[![Gem Version](https://badge.fury.io/rb/winrm-fs.svg)](http://badge.fury.io/rb/winrm-fs)
|
4
|
-
[![Build status](https://ci.appveyor.com/api/projects/status/wm6apa8ojfhfmwsf?svg=true)](https://ci.appveyor.com/project/winrb/winrm-fs)
|
5
|
-
|
6
|
-
## Uploading files
|
7
|
-
Files may be copied from the local machine to the winrm endpoint. Individual files or directories, as well as arrays of files and directories may be specified:
|
8
|
-
```ruby
|
9
|
-
require 'winrm-fs'
|
10
|
-
|
11
|
-
connection = WinRM::Connection.new(...
|
12
|
-
file_manager = WinRM::FS::FileManager.new(connection)
|
13
|
-
|
14
|
-
# upload file.txt from the current working directory
|
15
|
-
file_manager.upload('file.txt', 'c:/file.txt')
|
16
|
-
|
17
|
-
# upload the my_dir directory to c:/foo/my_dir
|
18
|
-
file_manager.upload('/Users/sneal/my_dir', 'c:/foo/my_dir')
|
19
|
-
|
20
|
-
# upload multiple directories and a file to c:\programData
|
21
|
-
file_manager.upload([
|
22
|
-
'/Users/sneal/foo1',
|
23
|
-
'/Users/sneal/foo2'
|
24
|
-
'/Users/sneal/fluffy.txt'
|
25
|
-
], '$env:ProgramData')
|
26
|
-
```
|
27
|
-
|
28
|
-
### Optimizing WinRM settings
|
29
|
-
Since winrm-fs 1.0/winrm 2.0, files are uploaded using the PSRP protocol and transfer speeds are dramatically improved from previous versions. This is largely due to the fact that the size of chunks that can be transferred at one time are now governed by the `MaxEnvelopeSizekb` winrm configuration setting on the endpoint. This default to 500 on Windows 2012 R2 and 150 on Windows 2008 R2. You may experience much faster transfer rates on 2008 R2 by increasing this setting.
|
30
|
-
|
31
|
-
### Handling progress events
|
32
|
-
If you want to implement your own custom progress handling, you can pass a code
|
33
|
-
block and use the proggress data that `upload` yields to this block:
|
34
|
-
```ruby
|
35
|
-
file_manager.upload('c:/dev/my_dir', '$env:AppData') do |bytes_copied, total_bytes, local_path, remote_path|
|
36
|
-
puts "#{bytes_copied}bytes of #{total_bytes}bytes copied"
|
37
|
-
end
|
38
|
-
```
|
39
|
-
|
40
|
-
## Troubleshooting
|
41
|
-
|
42
|
-
If you're having trouble, first of all its most likely a network or WinRM configuration
|
43
|
-
issue. Take a look at the [WinRM gem troubleshooting](https://github.com/WinRb/WinRM#troubleshooting)
|
44
|
-
first.
|
45
|
-
|
46
|
-
## Contributing
|
47
|
-
|
48
|
-
1. Fork it.
|
49
|
-
2. Create a branch (git checkout -b my_feature_branch)
|
50
|
-
3. Run the unit and integration tests (bundle exec rake integration)
|
51
|
-
4. Commit your changes (git commit -am "Added a sweet feature")
|
52
|
-
5. Push to the branch (git push origin my_feature_branch)
|
53
|
-
6. Create a pull requst from your branch into master (Please be sure to provide enough detail for us to cipher what this change is doing)
|
54
|
-
|
55
|
-
### Running the tests
|
56
|
-
|
57
|
-
We use Bundler to manage dependencies during development.
|
58
|
-
|
59
|
-
```
|
60
|
-
$ bundle install
|
61
|
-
```
|
62
|
-
|
63
|
-
Once you have the dependencies, you can run the unit tests with `rake`:
|
64
|
-
|
65
|
-
```
|
66
|
-
$ bundle exec rake spec
|
67
|
-
```
|
68
|
-
|
69
|
-
To run the integration tests you will need a Windows box with the WinRM service properly configured. Its easiest to use the Vagrant Windows box in the Vagrantilfe of this repo.
|
70
|
-
|
71
|
-
1. Create a Windows VM with WinRM configured (see above).
|
72
|
-
2. Copy the config-example.yml to config.yml - edit this file with your WinRM connection details.
|
73
|
-
3. Run `bundle exec rake integration`
|
74
|
-
|
75
|
-
## WinRM-fs Authors
|
76
|
-
* Shawn Neal (https://github.com/sneal)
|
77
|
-
* Matt Wrock (https://github.com/mwrock)
|
78
|
-
|
79
|
-
[Contributors](https://github.com/WinRb/winrm-fs/graphs/contributors)
|
1
|
+
# File system operations over Windows Remote Management (WinRM) for Ruby
|
2
|
+
[![Build Status](https://travis-ci.org/WinRb/winrm-fs.svg?branch=master)](https://travis-ci.org/WinRb/winrm-fs)
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/winrm-fs.svg)](http://badge.fury.io/rb/winrm-fs)
|
4
|
+
[![Build status](https://ci.appveyor.com/api/projects/status/wm6apa8ojfhfmwsf?svg=true)](https://ci.appveyor.com/project/winrb/winrm-fs)
|
5
|
+
|
6
|
+
## Uploading files
|
7
|
+
Files may be copied from the local machine to the winrm endpoint. Individual files or directories, as well as arrays of files and directories may be specified:
|
8
|
+
```ruby
|
9
|
+
require 'winrm-fs'
|
10
|
+
|
11
|
+
connection = WinRM::Connection.new(...
|
12
|
+
file_manager = WinRM::FS::FileManager.new(connection)
|
13
|
+
|
14
|
+
# upload file.txt from the current working directory
|
15
|
+
file_manager.upload('file.txt', 'c:/file.txt')
|
16
|
+
|
17
|
+
# upload the my_dir directory to c:/foo/my_dir
|
18
|
+
file_manager.upload('/Users/sneal/my_dir', 'c:/foo/my_dir')
|
19
|
+
|
20
|
+
# upload multiple directories and a file to c:\programData
|
21
|
+
file_manager.upload([
|
22
|
+
'/Users/sneal/foo1',
|
23
|
+
'/Users/sneal/foo2'
|
24
|
+
'/Users/sneal/fluffy.txt'
|
25
|
+
], '$env:ProgramData')
|
26
|
+
```
|
27
|
+
|
28
|
+
### Optimizing WinRM settings
|
29
|
+
Since winrm-fs 1.0/winrm 2.0, files are uploaded using the PSRP protocol and transfer speeds are dramatically improved from previous versions. This is largely due to the fact that the size of chunks that can be transferred at one time are now governed by the `MaxEnvelopeSizekb` winrm configuration setting on the endpoint. This default to 500 on Windows 2012 R2 and 150 on Windows 2008 R2. You may experience much faster transfer rates on 2008 R2 by increasing this setting.
|
30
|
+
|
31
|
+
### Handling progress events
|
32
|
+
If you want to implement your own custom progress handling, you can pass a code
|
33
|
+
block and use the proggress data that `upload` yields to this block:
|
34
|
+
```ruby
|
35
|
+
file_manager.upload('c:/dev/my_dir', '$env:AppData') do |bytes_copied, total_bytes, local_path, remote_path|
|
36
|
+
puts "#{bytes_copied}bytes of #{total_bytes}bytes copied"
|
37
|
+
end
|
38
|
+
```
|
39
|
+
|
40
|
+
## Troubleshooting
|
41
|
+
|
42
|
+
If you're having trouble, first of all its most likely a network or WinRM configuration
|
43
|
+
issue. Take a look at the [WinRM gem troubleshooting](https://github.com/WinRb/WinRM#troubleshooting)
|
44
|
+
first.
|
45
|
+
|
46
|
+
## Contributing
|
47
|
+
|
48
|
+
1. Fork it.
|
49
|
+
2. Create a branch (git checkout -b my_feature_branch)
|
50
|
+
3. Run the unit and integration tests (bundle exec rake integration)
|
51
|
+
4. Commit your changes (git commit -am "Added a sweet feature")
|
52
|
+
5. Push to the branch (git push origin my_feature_branch)
|
53
|
+
6. Create a pull requst from your branch into master (Please be sure to provide enough detail for us to cipher what this change is doing)
|
54
|
+
|
55
|
+
### Running the tests
|
56
|
+
|
57
|
+
We use Bundler to manage dependencies during development.
|
58
|
+
|
59
|
+
```
|
60
|
+
$ bundle install
|
61
|
+
```
|
62
|
+
|
63
|
+
Once you have the dependencies, you can run the unit tests with `rake`:
|
64
|
+
|
65
|
+
```
|
66
|
+
$ bundle exec rake spec
|
67
|
+
```
|
68
|
+
|
69
|
+
To run the integration tests you will need a Windows box with the WinRM service properly configured. Its easiest to use the Vagrant Windows box in the Vagrantilfe of this repo.
|
70
|
+
|
71
|
+
1. Create a Windows VM with WinRM configured (see above).
|
72
|
+
2. Copy the config-example.yml to config.yml - edit this file with your WinRM connection details.
|
73
|
+
3. Run `bundle exec rake integration`
|
74
|
+
|
75
|
+
## WinRM-fs Authors
|
76
|
+
* Shawn Neal (https://github.com/sneal)
|
77
|
+
* Matt Wrock (https://github.com/mwrock)
|
78
|
+
|
79
|
+
[Contributors](https://github.com/WinRb/winrm-fs/graphs/contributors)
|
data/Rakefile
CHANGED
@@ -1,28 +1,28 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
require 'rubygems'
|
3
|
-
require 'bundler/setup'
|
4
|
-
require 'rspec/core/rake_task'
|
5
|
-
require 'rubocop/rake_task'
|
6
|
-
|
7
|
-
# Change to the directory of this file.
|
8
|
-
Dir.chdir(File.expand_path('../', __FILE__))
|
9
|
-
|
10
|
-
# For gem creation and bundling
|
11
|
-
require 'bundler/gem_tasks'
|
12
|
-
|
13
|
-
RSpec::Core::RakeTask.new(:spec) do |task|
|
14
|
-
task.pattern = 'spec/unit/*_spec.rb'
|
15
|
-
task.rspec_opts = ['--color', '-f documentation']
|
16
|
-
end
|
17
|
-
|
18
|
-
# Run the integration test suite
|
19
|
-
RSpec::Core::RakeTask.new(:integration) do |task|
|
20
|
-
task.pattern = 'spec/integration/*_spec.rb'
|
21
|
-
task.rspec_opts = ['--color', '-f documentation']
|
22
|
-
end
|
23
|
-
|
24
|
-
RuboCop::RakeTask.new
|
25
|
-
|
26
|
-
task default: [:spec, :rubocop]
|
27
|
-
|
28
|
-
task all: [:default, :integration]
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'rubygems'
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
require 'rubocop/rake_task'
|
6
|
+
|
7
|
+
# Change to the directory of this file.
|
8
|
+
Dir.chdir(File.expand_path('../', __FILE__))
|
9
|
+
|
10
|
+
# For gem creation and bundling
|
11
|
+
require 'bundler/gem_tasks'
|
12
|
+
|
13
|
+
RSpec::Core::RakeTask.new(:spec) do |task|
|
14
|
+
task.pattern = 'spec/unit/*_spec.rb'
|
15
|
+
task.rspec_opts = ['--color', '-f documentation']
|
16
|
+
end
|
17
|
+
|
18
|
+
# Run the integration test suite
|
19
|
+
RSpec::Core::RakeTask.new(:integration) do |task|
|
20
|
+
task.pattern = 'spec/integration/*_spec.rb'
|
21
|
+
task.rspec_opts = ['--color', '-f documentation']
|
22
|
+
end
|
23
|
+
|
24
|
+
RuboCop::RakeTask.new
|
25
|
+
|
26
|
+
task default: [:spec, :rubocop]
|
27
|
+
|
28
|
+
task all: [:default, :integration]
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.2
|
data/Vagrantfile
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
# -*- mode: ruby -*-
|
3
|
-
# vi: set ft=ruby :
|
4
|
-
|
5
|
-
VAGRANTFILE_API_VERSION = '2'
|
6
|
-
|
7
|
-
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
8
|
-
config.vm.box = 'mwrock/WindowsNano'
|
9
|
-
end
|
1
|
+
# encoding: UTF-8
|
2
|
+
# -*- mode: ruby -*-
|
3
|
+
# vi: set ft=ruby :
|
4
|
+
|
5
|
+
VAGRANTFILE_API_VERSION = '2'
|
6
|
+
|
7
|
+
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
8
|
+
config.vm.box = 'mwrock/WindowsNano'
|
9
|
+
end
|
data/appveyor.yml
CHANGED
@@ -1,39 +1,39 @@
|
|
1
|
-
version: "master-{build}"
|
2
|
-
|
3
|
-
os: Windows Server 2012 R2
|
4
|
-
platform:
|
5
|
-
- x64
|
6
|
-
|
7
|
-
environment:
|
8
|
-
winrm_user: test_user
|
9
|
-
winrm_password: Pass@word1
|
10
|
-
|
11
|
-
matrix:
|
12
|
-
- ruby_version: "21"
|
13
|
-
winrm_endpoint: http://localhost:5985/wsman
|
14
|
-
|
15
|
-
clone_folder: c:\projects\winrm-fs
|
16
|
-
clone_depth: 1
|
17
|
-
branches:
|
18
|
-
only:
|
19
|
-
- master
|
20
|
-
|
21
|
-
install:
|
22
|
-
- ps: net user /add $env:winrm_user $env:winrm_password
|
23
|
-
- ps: net localgroup administrators $env:winrm_user /add
|
24
|
-
- ps: winrm set winrm/config/client/auth '@{Basic="true"}'
|
25
|
-
- ps: winrm set winrm/config/service/auth '@{Basic="true"}'
|
26
|
-
- ps: winrm set winrm/config/service '@{AllowUnencrypted="true"}'
|
27
|
-
- ps: $env:PATH="C:\Ruby$env:ruby_version\bin;$env:PATH"
|
28
|
-
- ps: Write-Host $env:PATH
|
29
|
-
- ps: ruby --version
|
30
|
-
- ps: gem --version
|
31
|
-
- ps: gem install bundler --quiet --no-ri --no-rdoc
|
32
|
-
- ps: bundler --version
|
33
|
-
|
34
|
-
build_script:
|
35
|
-
- bundle install || bundle install || bundle install
|
36
|
-
|
37
|
-
test_script:
|
38
|
-
- SET SPEC_OPTS=--format progress
|
39
|
-
- bundle exec rake integration
|
1
|
+
version: "master-{build}"
|
2
|
+
|
3
|
+
os: Windows Server 2012 R2
|
4
|
+
platform:
|
5
|
+
- x64
|
6
|
+
|
7
|
+
environment:
|
8
|
+
winrm_user: test_user
|
9
|
+
winrm_password: Pass@word1
|
10
|
+
|
11
|
+
matrix:
|
12
|
+
- ruby_version: "21"
|
13
|
+
winrm_endpoint: http://localhost:5985/wsman
|
14
|
+
|
15
|
+
clone_folder: c:\projects\winrm-fs
|
16
|
+
clone_depth: 1
|
17
|
+
branches:
|
18
|
+
only:
|
19
|
+
- master
|
20
|
+
|
21
|
+
install:
|
22
|
+
- ps: net user /add $env:winrm_user $env:winrm_password
|
23
|
+
- ps: net localgroup administrators $env:winrm_user /add
|
24
|
+
- ps: winrm set winrm/config/client/auth '@{Basic="true"}'
|
25
|
+
- ps: winrm set winrm/config/service/auth '@{Basic="true"}'
|
26
|
+
- ps: winrm set winrm/config/service '@{AllowUnencrypted="true"}'
|
27
|
+
- ps: $env:PATH="C:\Ruby$env:ruby_version\bin;$env:PATH"
|
28
|
+
- ps: Write-Host $env:PATH
|
29
|
+
- ps: ruby --version
|
30
|
+
- ps: gem --version
|
31
|
+
- ps: gem install bundler --quiet --no-ri --no-rdoc
|
32
|
+
- ps: bundler --version
|
33
|
+
|
34
|
+
build_script:
|
35
|
+
- bundle install || bundle install || bundle install
|
36
|
+
|
37
|
+
test_script:
|
38
|
+
- SET SPEC_OPTS=--format progress
|
39
|
+
- bundle exec rake integration
|
data/bin/rwinrmcp
CHANGED
@@ -1,86 +1,86 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
#
|
4
|
-
# Copyright 2014 Shawn Neal <sneal@sneal.net>
|
5
|
-
#
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License.
|
8
|
-
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
-
# See the License for the specific language governing permissions and
|
16
|
-
# limitations under the License.
|
17
|
-
|
18
|
-
# TODO: refactor this
|
19
|
-
# rubocop:disable all
|
20
|
-
|
21
|
-
$LOAD_PATH.push File.expand_path('../../lib', __FILE__)
|
22
|
-
|
23
|
-
require 'io/console'
|
24
|
-
require 'winrm-fs'
|
25
|
-
|
26
|
-
def help_msg
|
27
|
-
puts 'Usage: rwinrmcp sourcefile user@host:directory/targetfile'
|
28
|
-
puts ''
|
29
|
-
end
|
30
|
-
|
31
|
-
def parse_options
|
32
|
-
options = {}
|
33
|
-
fail 'Missing required options' unless ARGV.length == 2
|
34
|
-
|
35
|
-
options[:source_path] = ARGV[0]
|
36
|
-
fail "Cannot find source file: #{options[:source_path]}" unless \
|
37
|
-
File.exist?(options[:source_path])
|
38
|
-
|
39
|
-
m = /^(?<user>[a-z0-9\.\!\$ _-]+)@{1}(?<host>[a-z0-9\.\-]+)(?<port>:[0-9]+)?:{1}(?<file>.+)/i.match(ARGV[1])
|
40
|
-
fail "#{ARGV[1]} is an invalid destination" unless m
|
41
|
-
options[:user] = m[:user]
|
42
|
-
options[:endpoint] = "http://#{m[:host]}#{m[:port] || ':5985'}/wsman"
|
43
|
-
options[:dest_path] = m[:file]
|
44
|
-
|
45
|
-
# Get the password
|
46
|
-
print 'Password: '
|
47
|
-
options[:pass] = STDIN.noecho(&:gets).chomp
|
48
|
-
puts
|
49
|
-
|
50
|
-
# Set some defaults required by WinRM WS
|
51
|
-
options[:auth_type] = :plaintext
|
52
|
-
options[:basic_auth_only] = true
|
53
|
-
|
54
|
-
options
|
55
|
-
rescue StandardError => e
|
56
|
-
puts e.message
|
57
|
-
help_msg
|
58
|
-
exit 1
|
59
|
-
end
|
60
|
-
|
61
|
-
def file_manager(options)
|
62
|
-
service = WinRM::WinRMWebService.new(
|
63
|
-
options[:endpoint],
|
64
|
-
options[:auth_type].to_sym,
|
65
|
-
options)
|
66
|
-
WinRM::FS::FileManager.new(service)
|
67
|
-
end
|
68
|
-
|
69
|
-
def run(options)
|
70
|
-
bytes = file_manager(options).upload(options[:source_path], options[:dest_path])
|
71
|
-
puts "#{bytes} total bytes transfered"
|
72
|
-
exit 0
|
73
|
-
rescue Interrupt
|
74
|
-
puts 'exiting'
|
75
|
-
# ctrl-c
|
76
|
-
rescue WinRM::WinRMAuthorizationError
|
77
|
-
puts 'Authentication failed, bad user name or password'
|
78
|
-
exit 1
|
79
|
-
rescue StandardError => e
|
80
|
-
puts e.message
|
81
|
-
exit 1
|
82
|
-
end
|
83
|
-
|
84
|
-
run(parse_options)
|
85
|
-
|
86
|
-
# rubocop:enable all
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
#
|
4
|
+
# Copyright 2014 Shawn Neal <sneal@sneal.net>
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
|
18
|
+
# TODO: refactor this
|
19
|
+
# rubocop:disable all
|
20
|
+
|
21
|
+
$LOAD_PATH.push File.expand_path('../../lib', __FILE__)
|
22
|
+
|
23
|
+
require 'io/console'
|
24
|
+
require 'winrm-fs'
|
25
|
+
|
26
|
+
def help_msg
|
27
|
+
puts 'Usage: rwinrmcp sourcefile user@host:directory/targetfile'
|
28
|
+
puts ''
|
29
|
+
end
|
30
|
+
|
31
|
+
def parse_options
|
32
|
+
options = {}
|
33
|
+
fail 'Missing required options' unless ARGV.length == 2
|
34
|
+
|
35
|
+
options[:source_path] = ARGV[0]
|
36
|
+
fail "Cannot find source file: #{options[:source_path]}" unless \
|
37
|
+
File.exist?(options[:source_path])
|
38
|
+
|
39
|
+
m = /^(?<user>[a-z0-9\.\!\$ _-]+)@{1}(?<host>[a-z0-9\.\-]+)(?<port>:[0-9]+)?:{1}(?<file>.+)/i.match(ARGV[1])
|
40
|
+
fail "#{ARGV[1]} is an invalid destination" unless m
|
41
|
+
options[:user] = m[:user]
|
42
|
+
options[:endpoint] = "http://#{m[:host]}#{m[:port] || ':5985'}/wsman"
|
43
|
+
options[:dest_path] = m[:file]
|
44
|
+
|
45
|
+
# Get the password
|
46
|
+
print 'Password: '
|
47
|
+
options[:pass] = STDIN.noecho(&:gets).chomp
|
48
|
+
puts
|
49
|
+
|
50
|
+
# Set some defaults required by WinRM WS
|
51
|
+
options[:auth_type] = :plaintext
|
52
|
+
options[:basic_auth_only] = true
|
53
|
+
|
54
|
+
options
|
55
|
+
rescue StandardError => e
|
56
|
+
puts e.message
|
57
|
+
help_msg
|
58
|
+
exit 1
|
59
|
+
end
|
60
|
+
|
61
|
+
def file_manager(options)
|
62
|
+
service = WinRM::WinRMWebService.new(
|
63
|
+
options[:endpoint],
|
64
|
+
options[:auth_type].to_sym,
|
65
|
+
options)
|
66
|
+
WinRM::FS::FileManager.new(service)
|
67
|
+
end
|
68
|
+
|
69
|
+
def run(options)
|
70
|
+
bytes = file_manager(options).upload(options[:source_path], options[:dest_path])
|
71
|
+
puts "#{bytes} total bytes transfered"
|
72
|
+
exit 0
|
73
|
+
rescue Interrupt
|
74
|
+
puts 'exiting'
|
75
|
+
# ctrl-c
|
76
|
+
rescue WinRM::WinRMAuthorizationError
|
77
|
+
puts 'Authentication failed, bad user name or password'
|
78
|
+
exit 1
|
79
|
+
rescue StandardError => e
|
80
|
+
puts e.message
|
81
|
+
exit 1
|
82
|
+
end
|
83
|
+
|
84
|
+
run(parse_options)
|
85
|
+
|
86
|
+
# rubocop:enable all
|