spectre-ftp 2.0.0 → 2.0.2

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 +156 -24
  3. metadata +17 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 78abb94631853f8555a1c8140d6ff635d9c52da476df9fcca459b04bc4e56e7a
4
- data.tar.gz: 640cfafddb1a3c1893c8ce28d3ca85aa884e4ac0b82e368fcc015a9ff1c54eda
3
+ metadata.gz: b8d6f6f87bd1046313a344b49321de16b08d13dd057ef2d1a2c13341b65111d7
4
+ data.tar.gz: 1f10d7313743695c98dc595736aa7fd4566c9e4b47e73fad364f2daffdff1df0
5
5
  SHA512:
6
- metadata.gz: e0d15287e01e895a164404b1259a44e8ca0e06ef08c7da4d0a8d7992d6294df72d748177bc133ee72c904d0be6e8f3f60554c38e44d0bd65d24d22952d555957
7
- data.tar.gz: b39d5b16b6f081cb24eb3d49021a1075400b8379c71e25667cba32252f7dae078689281bca2739016cf6f5f057939088f41a2b47bede388cd6b2407c297593fa
6
+ metadata.gz: a5409c0acb1cefaf3b6cf392f7dfe6f6cefb97346eca7a078920c2c1f0ec84745bf5347b325bc2b8f0571d3f40e578d52c3212ac5dc5f253dc6acd9a4a7e85fa
7
+ data.tar.gz: f93d905e0264e1225716a24ace24aa944c667c5b4c887a7aed8412af0145692db462de5c3b8a5d1b437bf81dc273628a7c794f412b28de72e41b61f9f1287088
data/lib/spectre/ftp.rb CHANGED
@@ -66,12 +66,73 @@ module Spectre
66
66
  @__session.putbinaryfile(localfile, to)
67
67
  end
68
68
 
69
- def list
69
+ def list path = nil
70
70
  connect!
71
- file_list = @__session.list
72
- @__logger.info("Listing files in #{@__session.pwd}\n#{file_list}")
71
+ file_list = path ? @__session.list(path) : @__session.list
72
+ @__logger.info("Listing files in #{path || @__session.pwd}\n#{file_list}")
73
73
  file_list
74
74
  end
75
+
76
+ def mkdir dirname
77
+ connect!
78
+ @__logger.info("Creating directory '#{dirname}' in #{@__session.pwd}")
79
+ @__session.mkdir(dirname)
80
+ end
81
+
82
+ def rmdir dirname
83
+ connect!
84
+ @__logger.info("Removing directory '#{dirname}' in #{@__session.pwd}")
85
+ @__session.rmdir(dirname)
86
+ end
87
+
88
+ def delete filename
89
+ connect!
90
+ @__logger.info("Deleting file '#{filename}' in #{@__session.pwd}")
91
+ @__session.delete(filename)
92
+ end
93
+
94
+ def rename oldname, newname
95
+ connect!
96
+ @__logger.info("Renaming '#{oldname}' to '#{newname}' in #{@__session.pwd}")
97
+ @__session.rename(oldname, newname)
98
+ end
99
+
100
+ def chdir path
101
+ connect!
102
+ @__logger.info("Changing directory to '#{path}'")
103
+ @__session.chdir(path)
104
+ end
105
+
106
+ def pwd
107
+ connect!
108
+ current_dir = @__session.pwd
109
+ @__logger.info("Current directory: #{current_dir}")
110
+ current_dir
111
+ end
112
+
113
+ def exists path
114
+ connect!
115
+ begin
116
+ @__session.size(path)
117
+ true
118
+ rescue Net::FTPPermError, Net::FTPTempError
119
+ false
120
+ end
121
+ end
122
+
123
+ def file_size filename
124
+ connect!
125
+ size = @__session.size(filename)
126
+ @__logger.info("File size of '#{filename}': #{size} bytes")
127
+ size
128
+ end
129
+
130
+ def mtime filename
131
+ connect!
132
+ modification_time = @__session.mtime(filename)
133
+ @__logger.info("Modification time of '#{filename}': #{modification_time}")
134
+ modification_time
135
+ end
75
136
  end
76
137
 
77
138
  class SFTPConnection
@@ -144,6 +205,7 @@ module Spectre
144
205
  end
145
206
 
146
207
  def exists path
208
+ connect!
147
209
  begin
148
210
  @__session.stat! path
149
211
  rescue Net::SFTP::StatusException => e
@@ -154,6 +216,71 @@ module Spectre
154
216
 
155
217
  true
156
218
  end
219
+
220
+ def list path = '.'
221
+ connect!
222
+ files = []
223
+ @__session.dir.foreach(path) do |entry|
224
+ files << entry.longname
225
+ end
226
+ @__logger.info("Listing files in #{path}\n#{files}")
227
+ files
228
+ end
229
+
230
+ def mkdir dirname
231
+ connect!
232
+ @__logger.info("Creating directory '#{dirname}'")
233
+ @__session.mkdir!(dirname)
234
+ end
235
+
236
+ def rmdir dirname
237
+ connect!
238
+ @__logger.info("Removing directory '#{dirname}'")
239
+ @__session.rmdir!(dirname)
240
+ end
241
+
242
+ def delete filename
243
+ connect!
244
+ @__logger.info("Deleting file '#{filename}'")
245
+ @__session.remove!(filename)
246
+ end
247
+
248
+ def rename oldname, newname
249
+ connect!
250
+ @__logger.info("Renaming '#{oldname}' to '#{newname}'")
251
+ @__session.rename!(oldname, newname)
252
+ end
253
+
254
+ # # SFTP is stateless and doesn't have a concept of current directory
255
+ # # All operations use absolute paths or paths relative to the user's home directory
256
+ # # This method is a no-op for API compatibility with FTP
257
+ # def chdir path
258
+ # connect!
259
+ # @__logger.info("Note: SFTP is stateless - paths are always absolute or relative to home directory")
260
+ # end
261
+
262
+ def pwd
263
+ connect!
264
+ current_dir = @__session.realpath!('.')
265
+ @__logger.info("Current directory: #{current_dir.name}")
266
+ current_dir.name
267
+ end
268
+
269
+ def file_size filename
270
+ connect!
271
+ stat_info = @__session.stat!(filename)
272
+ size = stat_info.size
273
+ @__logger.info("File size of '#{filename}': #{size} bytes")
274
+ size
275
+ end
276
+
277
+ def mtime filename
278
+ connect!
279
+ stat_info = @__session.stat!(filename)
280
+ modification_time = Time.at(stat_info.mtime)
281
+ @__logger.info("Modification time of '#{filename}': #{modification_time}")
282
+ modification_time
283
+ end
157
284
  end
158
285
 
159
286
  class Client
@@ -164,18 +291,24 @@ module Spectre
164
291
  @logger = logger
165
292
  end
166
293
 
294
+ def ftps(name, config = {}, &)
295
+ config[:ssl] ||= { implicit: true }
296
+ config[:port] ||= 990
297
+
298
+ ftp(name, config, &)
299
+ end
300
+
167
301
  def ftp(name, config = {}, &)
168
302
  cfg = @config[name] || {}
169
303
 
170
- host = config[:host] || cfg['host'] || name
171
- username = config[:username] || cfg['username']
172
- password = config[:password] || cfg['password']
304
+ hostname = config.delete(:host) || cfg['host'] || name
305
+ username = config.delete(:username) || cfg['username']
306
+ password = config.delete(:password) || cfg['password']
173
307
 
174
- opts = {}
175
- opts[:ssl] = config[:ssl]
176
- opts[:port] = config[:port] || cfg['port'] || 21
308
+ config[:port] = config[:port] || cfg['port'] || 21
309
+ config[:ssl] = config[:ssl] || cfg['ssl']
177
310
 
178
- ftp_conn = FTPConnection.new(host, username, password, opts, @logger)
311
+ ftp_conn = FTPConnection.new(hostname, username, password, config, @logger)
179
312
 
180
313
  begin
181
314
  ftp_conn.instance_eval(&)
@@ -187,23 +320,22 @@ module Spectre
187
320
  def sftp(name, config = {}, &)
188
321
  cfg = @config[name] || {}
189
322
 
190
- host = config[:host] || cfg['host'] || name
191
- username = config[:username] || cfg['username']
192
- password = config[:password] || cfg['password']
323
+ host = config.delete(:host) || cfg['host'] || name
324
+ username = config.delete(:username) || cfg['username']
325
+ password = config.delete(:password) || cfg['password']
193
326
 
194
- opts = {}
195
- opts[:password] = password
196
- opts[:port] = config[:port] || cfg['port'] || 22
197
- opts[:keys] = [cfg['key']] if cfg.key? 'key'
198
- opts[:passphrase] = cfg['passphrase'] if cfg.key? 'passphrase'
327
+ config[:password] = password
328
+ config[:port] ||= cfg['port'] || 22
329
+ config[:keys] = [cfg['key']] if cfg.key? 'key'
330
+ config[:passphrase] = cfg['passphrase'] if cfg.key? 'passphrase'
199
331
 
200
- opts[:auth_methods] = []
201
- opts[:auth_methods].push 'publickey' if opts[:keys]
202
- opts[:auth_methods].push 'password' if opts[:password]
332
+ config[:auth_methods] = []
333
+ config[:auth_methods].push 'publickey' if config[:keys]
334
+ config[:auth_methods].push 'password' if config[:password]
203
335
 
204
- opts[:non_interactive] = true
336
+ config[:non_interactive] = true
205
337
 
206
- sftp_con = SFTPConnection.new(host, username, opts, @logger)
338
+ sftp_con = SFTPConnection.new(host, username, config, @logger)
207
339
 
208
340
  begin
209
341
  sftp_con.instance_eval(&)
@@ -214,5 +346,5 @@ module Spectre
214
346
  end
215
347
  end
216
348
 
217
- Engine.register(FTP::Client, :ftp, :sftp) if defined? Engine
349
+ Engine.register(FTP::Client, :ftp, :sftp, :ftps) if defined? Engine
218
350
  end
metadata CHANGED
@@ -1,14 +1,28 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spectre-ftp
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Neubauer
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-03-21 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: logger
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
12
26
  - !ruby/object:Gem::Dependency
13
27
  name: net-ftp
14
28
  requirement: !ruby/object:Gem::Requirement
@@ -66,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
80
  - !ruby/object:Gem::Version
67
81
  version: '0'
68
82
  requirements: []
69
- rubygems_version: 3.6.6
83
+ rubygems_version: 3.6.9
70
84
  specification_version: 4
71
85
  summary: Standalone FTP wrapper compatible with spectre
72
86
  test_files: []