spectre-ftp 1.0.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/spectre/ftp.rb +39 -15
  3. metadata +33 -20
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 13456bf294907a5b79f995804c119d803a1a565e6b93520d924ee7429e0defca
4
- data.tar.gz: edaa3c30ad479bfe490086f9d3ec6268befa9b6cd26b445790f403cc4884aafe
3
+ metadata.gz: 7a902a8c177730c407b7828f6b60d6bf592402d2b7b5b6103b2c13fdb1ca77ce
4
+ data.tar.gz: a7612890b94aafb60c3723e0b9515ea0f8859d62578f0ce1cee30767517d41fc
5
5
  SHA512:
6
- metadata.gz: 5105ff5be1c42b1d163ebea6b5844b770df74be2cb1f97ab1f239e89c9837c939ad6f115688bd105da273ffda6b41e8ece9cbd83b999b6f4a69c4977258380e1
7
- data.tar.gz: 3310db259c6786404503daff0a05286c60c9aa1af01eae59c85e9aab2e27c76ec22bb7d4ff2018328a9139b254086e11ab6586f682c92f4f3942aa7fb41b4172
6
+ metadata.gz: 2680bc0403cf0eb0e57a039bd42103a72de3b1d8ea303f1a39a00100ff978932c7c6c317fe99333a2c858f7325b90a7b0bf14b56923aac8accd8c007aa91be08
7
+ data.tar.gz: 739171c88d9513517b143f4d106b2d352457d914a373653093494d93ac89e8aa817badf8fc3dbdaa8b37ab5bde3d8be2d8559285409cef5949c24374da1c6f05
data/lib/spectre/ftp.rb CHANGED
@@ -19,8 +19,17 @@ module Spectre
19
19
  @__opts = opts
20
20
  end
21
21
 
22
+ def username user
23
+ @__username = user
24
+ end
25
+
26
+ def password pass
27
+ @__password = pass
28
+ end
29
+
22
30
  def connect!
23
31
  return unless @__session == nil or @__session.closed?
32
+
24
33
  @__logger.info "Connecting to '#{@__host}' with user '#{@__username}'"
25
34
  @__session = Net::FTP.new(@__host, @__opts)
26
35
  @__session.login @__username, @__password
@@ -28,6 +37,7 @@ module Spectre
28
37
 
29
38
  def close
30
39
  return unless @__session and not @__session.closed?
40
+
31
41
  @__session.close
32
42
  end
33
43
 
@@ -42,25 +52,24 @@ module Spectre
42
52
 
43
53
  def download remotefile, to: File.basename(remotefile)
44
54
  connect!
45
- @__logger.info "Downloading '#{@__username}@#{@__host}:#{File.join @__session.pwd, remotefile}' to '#{File.expand_path to}'"
55
+ @__logger.info("Downloading '#{@__username}@#{@__host}:#{File.join @__session.pwd, remotefile}' to '#{File.expand_path to}'")
46
56
  @__session.getbinaryfile(remotefile, to)
47
57
  end
48
58
 
49
59
  def upload localfile, to: File.basename(localfile)
50
60
  connect!
51
- @__logger.info "Uploading '#{File.expand_path localfile}' to '#{@__username}@#{@__host}:#{File.join @__session.pwd, to}'"
61
+ @__logger.info("Uploading '#{File.expand_path localfile}' to '#{@__username}@#{@__host}:#{File.join @__session.pwd, to}'")
52
62
  @__session.putbinaryfile(localfile, to)
53
63
  end
54
64
 
55
65
  def list
56
66
  connect!
57
67
  file_list = @__session.list
58
- @__logger.info "Listing file in #{@__session.pwd}\n#{file_list}"
68
+ @__logger.info("Listing files in #{@__session.pwd}\n#{file_list}")
59
69
  file_list
60
70
  end
61
71
  end
62
72
 
63
-
64
73
  class SFTPConnection < DslClass
65
74
  def initialize host, username, opts, logger
66
75
  opts[:non_interactive] = true
@@ -72,8 +81,27 @@ module Spectre
72
81
  @__opts = opts
73
82
  end
74
83
 
84
+ def username user
85
+ @__username = user
86
+ end
87
+
88
+ def password pass
89
+ @__opts[:password] = pass
90
+ @__opts[:auth_methods].push 'password' unless @__opts[:auth_methods].include? 'password'
91
+ end
92
+
93
+ def private_key file_path
94
+ @__opts[:keys] = [file_path]
95
+ @__opts[:auth_methods].push 'publickey' unless @__opts[:auth_methods].include? 'publickey'
96
+ end
97
+
98
+ def passphrase phrase
99
+ @__opts[:passphrase] = phrase
100
+ end
101
+
75
102
  def connect!
76
103
  return unless @__session == nil or @__session.closed?
104
+
77
105
  @__logger.info "Connecting to '#{@__host}' with user '#{@__username}'"
78
106
  @__session = Net::SFTP.start(@__host, @__username, @__opts)
79
107
  @__session.connect!
@@ -81,6 +109,7 @@ module Spectre
81
109
 
82
110
  def close
83
111
  return unless @__session and not @__session.closed?
112
+
84
113
  # @__session.close!
85
114
  end
86
115
 
@@ -94,14 +123,14 @@ module Spectre
94
123
  end
95
124
 
96
125
  def download remotefile, to: File.basename(remotefile)
97
- @__logger.info "Downloading '#{@__username}@#{@__host}:#{remotefile}' to '#{File.expand_path to}'"
98
126
  connect!
127
+ @__logger.info "Downloading '#{@__username}@#{@__host}:#{remotefile}' to '#{File.expand_path to}'"
99
128
  @__session.download!(remotefile, to)
100
129
  end
101
130
 
102
131
  def upload localfile, to: File.basename(localfile)
103
- @__logger.info "Uploading '#{File.expand_path localfile}' to '#{@__username}@#{@__host}:#{to}'"
104
132
  connect!
133
+ @__logger.info "Uploading '#{File.expand_path localfile}' to '#{@__username}@#{@__host}:#{to}'"
105
134
  @__session.upload!(localfile, to)
106
135
  end
107
136
 
@@ -114,10 +143,10 @@ module Spectre
114
143
 
115
144
  def exists path
116
145
  begin
117
- file_info = @__session.stat! path
118
-
146
+ @__session.stat! path
119
147
  rescue Net::SFTP::StatusException => e
120
148
  return false if e.description == 'no such file'
149
+
121
150
  raise e
122
151
  end
123
152
 
@@ -128,7 +157,6 @@ module Spectre
128
157
 
129
158
  class << self
130
159
  def ftp name, config={}, &block
131
- raise "FTP connection '#{name}' not configured" unless @@cfg.key?(name) or config.count > 0
132
160
  cfg = @@cfg[name] || {}
133
161
 
134
162
  host = config[:host] || cfg['host'] || name
@@ -139,8 +167,6 @@ module Spectre
139
167
  opts[:ssl] = config[:ssl]
140
168
  opts[:port] = config[:port] || cfg['port'] || 21
141
169
 
142
- @@logger.info "Connecting to #{host} with user #{username}"
143
-
144
170
  ftp_conn = FTPConnection.new(host, username, password, opts, @@logger)
145
171
 
146
172
  begin
@@ -151,8 +177,6 @@ module Spectre
151
177
  end
152
178
 
153
179
  def sftp name, config={}, &block
154
- raise "FTP connection '#{name}' not configured" unless @@cfg.key?(name) or config.count > 0
155
-
156
180
  cfg = @@cfg[name] || {}
157
181
 
158
182
  host = config[:host] || cfg['host'] || name
@@ -180,7 +204,7 @@ module Spectre
180
204
  end
181
205
 
182
206
  Spectre.register do |config|
183
- @@logger = ::Logger.new config['log_file'], progname: 'spectre/ftp'
207
+ @@logger = Spectre::Logging::ModuleLogger.new(config, 'spectre/ftp')
184
208
 
185
209
  if config.key? 'ftp'
186
210
 
@@ -192,4 +216,4 @@ module Spectre
192
216
 
193
217
  Spectre.delegate :ftp, :sftp, to: self
194
218
  end
195
- end
219
+ end
metadata CHANGED
@@ -1,60 +1,73 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spectre-ftp
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Neubauer
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-30 00:00:00.000000000 Z
11
+ date: 2025-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: net-ftp
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: net-sftp
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
- - - "~>"
31
+ - - ">="
18
32
  - !ruby/object:Gem::Version
19
- version: 3.0.0
33
+ version: '0'
20
34
  type: :runtime
21
35
  prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
- - - "~>"
38
+ - - ">="
25
39
  - !ruby/object:Gem::Version
26
- version: 3.0.0
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: spectre-core
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - ">="
32
46
  - !ruby/object:Gem::Version
33
- version: 1.8.4
47
+ version: 1.14.0
34
48
  type: :runtime
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
52
  - - ">="
39
53
  - !ruby/object:Gem::Version
40
- version: 1.8.4
41
- description: Adds FTP access functionality to the spectre framework
54
+ version: 1.14.0
55
+ description: Adds FTP functionality to the spectre framework
42
56
  email:
43
- - me@christianneubauer.de
57
+ - christian.neubauer@ionos.com
44
58
  executables: []
45
59
  extensions: []
46
60
  extra_rdoc_files: []
47
61
  files:
48
62
  - lib/spectre/ftp.rb
49
- homepage: https://bitbucket.org/cneubaur/spectre-ftp
63
+ homepage: https://github.com/ionos-spectre/spectre-ftp
50
64
  licenses:
51
65
  - MIT
52
66
  metadata:
53
- allowed_push_host: https://rubygems.org/
54
- homepage_uri: https://bitbucket.org/cneubaur/spectre-ftp
55
- source_code_uri: https://bitbucket.org/cneubaur/spectre-ftp
56
- changelog_uri: https://bitbucket.org/cneubaur/spectre-ftp/src/master/CHANGELOG.md
57
- post_install_message:
67
+ homepage_uri: https://github.com/ionos-spectre/spectre-ftp
68
+ source_code_uri: https://github.com/ionos-spectre/spectre-ftp
69
+ changelog_uri: https://github.com/ionos-spectre/spectre-ftp/src/master/CHANGELOG.md
70
+ post_install_message:
58
71
  rdoc_options: []
59
72
  require_paths:
60
73
  - lib
@@ -62,15 +75,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
62
75
  requirements:
63
76
  - - ">="
64
77
  - !ruby/object:Gem::Version
65
- version: 2.5.0
78
+ version: 3.0.0
66
79
  required_rubygems_version: !ruby/object:Gem::Requirement
67
80
  requirements:
68
81
  - - ">="
69
82
  - !ruby/object:Gem::Version
70
83
  version: '0'
71
84
  requirements: []
72
- rubygems_version: 3.0.8
73
- signing_key:
85
+ rubygems_version: 3.4.19
86
+ signing_key:
74
87
  specification_version: 4
75
88
  summary: FTP module for spectre
76
89
  test_files: []