mymedia_ftp 0.1.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 1fcf82bafaf00c2c6b63959544fe165ba5e07a50
4
- data.tar.gz: 75a6c2ca3d8fa8cc3d30fb63080c3369e9870f5f
2
+ SHA256:
3
+ metadata.gz: fdfae1127b5532481e69af2799cecff89c08c092b5cdf6ff782b497a410c1aad
4
+ data.tar.gz: 9a026fec231bc2763a19e9ae1696daced22055bf58ad1789907c0c99d735d428
5
5
  SHA512:
6
- metadata.gz: 177f855f772f6478579ba796fb74b7c603015897481ced5a4f3f91c3514f354fa00b62b79f3a06e89236c510e0159c0ae2c3c7727cce40b6d787fc93af2b5418
7
- data.tar.gz: f3d77a20c1e4f50d3137969688de67b4151fb0236478f9f20554d32fde09148047be778c7b7a9309b5dcc1db3f2e96653394778910bfe3ac732c92b5119aa1ae
6
+ metadata.gz: 5a69a11adf2e762df3f40123a567eb80690e8514b3e53999d82386a41532d547ceb2be038ebb4b4dead8c167d503aedd5c431e441e9d6d402a85648e8a87dcd7
7
+ data.tar.gz: 9d61a3263591215ea6d0ef71499a6778d5ba9b8500e25ac71bcd5121e576bc67c72e964ebb456b38d5b10d722ec6b4d55146d938063704bbdfc870a42e541e57
@@ -1,2 +1,4 @@
1
- DAv0�q�{�f�Fbu��(Yz�� B�����I�R�."���n\y[e�zek�b��
2
- ƥc��}���Ac��G��mw�mU�p�}՝y�����jw�n *�w
1
+ :>{��ң̗ ��Qs ��۽�`<��H]5��/�*13�"|՜Y2&O��%���
2
+
3
+ T&�D\[SI��#��0:o99������j������fͣ�j�t��#;������<n��>f8��U z�'�{�&�`p��v� fkJ�6���d�K�����v��3�h��{�tgZ�G�.YzC�V�W��2
4
+ 4U�V��p'��+]�h���vp(�&�%���'�
data.tar.gz.sig CHANGED
Binary file
@@ -3,62 +3,205 @@
3
3
  # file: mymedia_ftp.rb
4
4
 
5
5
  require 'net/ftp'
6
+ require 'tempfile'
6
7
  require 'fileutils'
7
8
 
8
9
 
9
10
  class MyMediaFTP < Net::FTP
10
11
 
11
- def initialize(host: '127.0.0.1', user: 'user', password: '1234')
12
+ def self.cp(src, dest, debug: false)
13
+
14
+ if src =~ /^ftp:\/\// then
15
+ uri, remotepath = src.match(/^(ftp:\/\/[^\/]+)(\/[^$]+)/).captures
16
+ new(uri, debug: debug).cp(remotepath, dest, :inbound)
17
+ else
18
+ uri, remotepath = dest.match(/^(ftp:\/\/[^\/]+)(\/[^$]+)/).captures
19
+ new(uri, debug: debug).cp(src, remotepath, :outbound)
20
+ end
21
+
22
+ end
23
+
24
+ def self.ls(s, debug: false)
25
+
26
+ uri, remotepath = s.match(/^(ftp:\/\/[^\/]+)(\/[^$]*)/).captures
27
+ puts 'remotepath' + remotepath if debug
28
+ new(uri, debug: debug).ls(remotepath)
29
+
30
+ end
31
+
32
+ def self.read(s, debug: false)
33
+
34
+ uri, remotepath = s.match(/^(ftp:\/\/[^\/]+)(\/[^$]+)/).captures
35
+ ftp = new(uri, debug: debug)
36
+ p ftp if debug
37
+
38
+ tmpfile = Tempfile.new('ftp')
39
+
40
+ ftp.cp remotepath, tmpfile.path
41
+ File.read tmpfile.path
42
+
43
+ end
44
+
45
+ def self.rm(s, debug: false)
46
+
47
+ uri, remotepath = s.match(/^(ftp:\/\/[^\/]+)(\/[^$]+)/).captures
48
+ new(uri, debug: debug).rm(remotepath)
49
+
50
+ end
51
+
52
+ def initialize(s=nil, host: '127.0.0.1', user: 'user', password: '1234',
53
+ port: 21, debug: false)
54
+
55
+ if s then
56
+
57
+ r = s.match(/(?<user>\w+):(?<password>\w+)@(?<host>[^:]+)(?:\:(?<port>\d+))?/)
58
+ h = r.named_captures.map {|k,v| [k.to_sym, v]}.to_h
59
+ puts 'h: ' + h.inspect if debug
60
+ user, password, host = h.values.take(3)
61
+ port = h[:port] if h[:port]
62
+
63
+ end
64
+
65
+ @debug = debug
12
66
 
13
- @curdir = Dir.pwd
67
+ @curdir = '/'
14
68
  super()
15
- connect(host, 21)
69
+ connect(host, port)
16
70
  login(user, password)
17
71
 
18
72
  end
73
+
74
+ def chdir(dir)
75
+ super(dir)
76
+ @curdir = pwd
77
+ end
78
+
79
+ alias cd chdir
19
80
 
20
- def cp(src='', dest='')
81
+ def cp(src='', dest='', direction=:inbound, &blk)
21
82
 
83
+ return outbound_cp(src, dest) if direction == :outbound
84
+
85
+ puts 'cp: ' + src.inspect if @debug
22
86
  chdir File.dirname(src)
23
- FileUtils.mkdir_p dest
24
- Dir.chdir dest
25
-
26
- files = list_filenames(src)
27
-
28
- puts 'copying ...'
87
+ dir = File.dirname(dest)
88
+ FileUtils.mkdir_p dir
89
+ Dir.chdir dir
90
+
91
+ puts 'copying ...' if @debug
92
+
93
+ files = if src =~ /[\*\?]/ then
94
+
95
+ cp_files(src)
96
+
97
+ else
98
+
99
+ begin
100
+ getbinaryfile src, dest
101
+ rescue Net::FTPPermError => e
102
+ puts 'e: ' + e.inspect
103
+ end
104
+
105
+ end
29
106
 
30
- files.each do |x|
107
+ end
108
+
109
+ def delete(filename)
110
+ super(filename)
111
+ 'file deleted'
112
+ end
113
+
114
+ def list_filenames(s=@curdir+'/*')
115
+
116
+ if @debug
117
+ puts 'inside list_filenames'
118
+ puts 's: ' + s.inspect
119
+ end
120
+
121
+ if s =~ /\*/ then
122
+
123
+ src = File.dirname(s)
124
+
125
+ raw_q = File.basename(s)
126
+ puts 'raw_q: ' + raw_q.inspect if @debug
127
+
128
+ q = raw_q.gsub('.','\.').gsub('*','.*').gsub('?','.?')\
129
+ .sub(/[^\*\?\.]$/,'.*')
130
+ else
131
+ src = s
132
+ end
31
133
 
32
- puts x
33
- getbinaryfile x, x.downcase.gsub(/ +/,'-')
34
- yield(x) if block_given?
134
+ list(src).inject([]) do |r, x|
135
+
136
+ raw_attr, _, owner, group, filesize, month, day, time, filename = \
137
+ x.split(/ +/,9)
138
+ type = raw_attr =~ /d/ ? :directory : :file
139
+
140
+ if q then
141
+ filename[/^#{q}$/] ? r << {name: filename, type: type} : r
142
+ else
143
+ r << {name: filename, type: type}
144
+ end
145
+ r
35
146
  end
36
147
 
37
148
  end
38
-
149
+
150
+ alias ls list_filenames
39
151
 
40
152
  def mv(src='', dest='')
41
153
 
42
154
  puts 'moving ...'
43
- cp(src, dest) {|file| delete file }
44
-
155
+ cp(src, dest) do |file, type|
156
+ type == :file ? delete(file) : rmdir(file)
157
+ end
45
158
 
46
159
  end
47
-
160
+
161
+ alias rm delete
162
+
48
163
  private
49
-
50
- def list_filenames(src)
51
-
52
- raw_q = File.basename(src)
53
-
54
- q = raw_q.gsub('.','\.').gsub('*','.*').gsub('?','.?')
55
-
56
- list.inject([]) do |r, x|
57
-
58
- filename = x.split(/ +/,9).last
59
- filename[/^#{q}$/] ? r << filename : r
60
- end
61
-
164
+
165
+ def cp_dir(directory, &blk)
166
+
167
+ puts 'inside cp_dir: ' + directory.inspect if @debug
168
+ FileUtils.mkdir_p directory
169
+ parent_dir = pwd
170
+ chdir directory
171
+ cp('*', directory, &blk)
172
+ chdir parent_dir
173
+ end
174
+
175
+ def cp_files(src)
176
+
177
+ files = list_filenames(src)
178
+
179
+ files.each do |h|
180
+
181
+ name, type = h[:name], h[:type]
182
+
183
+ puts name
184
+
185
+ if type == :file then
186
+ begin
187
+ getbinaryfile name, name.downcase.gsub(/ +/,'-')
188
+ rescue Net::FTPPermError => e
189
+ puts 'e: ' + e.inspect
190
+ end
191
+ else
192
+ cp_dir(name, &blk)
193
+ end
194
+ blk.call(name, type) if block_given?
195
+ end
62
196
  end
63
197
 
198
+ def outbound_cp(src, destination='.')
199
+
200
+ if File.basename(destination) == '.' then
201
+ destination.sub!(/\.$/, File.basename(src))
202
+ end
203
+
204
+ putbinaryfile(src, destination)
205
+ end
206
+
64
207
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mymedia_ftp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -10,31 +10,35 @@ bindir: bin
10
10
  cert_chain:
11
11
  - |
12
12
  -----BEGIN CERTIFICATE-----
13
- MIIDljCCAn6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBIMRIwEAYDVQQDDAlnZW1t
14
- YXN0ZXIxHjAcBgoJkiaJk/IsZAEZFg5qYW1lc3JvYmVydHNvbjESMBAGCgmSJomT
15
- 8ixkARkWAmV1MB4XDTE1MDkyNDEyNDcwMloXDTE2MDkyMzEyNDcwMlowSDESMBAG
16
- A1UEAwwJZ2VtbWFzdGVyMR4wHAYKCZImiZPyLGQBGRYOamFtZXNyb2JlcnRzb24x
17
- EjAQBgoJkiaJk/IsZAEZFgJldTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
18
- ggEBALukh1F6BczdR6TwHdTUxw2jIyU7DkDFBqcVCQElX0s0iEbKbI9BbkPf0NA1
19
- +soTS6yrp3SGUvRLal9MKqh8WUz1eubz7wlhlVkcnDZK7H93nttpRuI9W5NbwM+i
20
- E4yR9YBzHww5YKOB1Nq8B20WF1MHI0aoKiNO6/4FZ1UwItKjJoykQR8IWhaM8Ful
21
- zYQcPyhjRYKVYvAJIoIdoyC4v4wVcmhefZPzfMxWSYir/eO1CE89SD41kIhStA04
22
- IZJt4WS16sfpxGtjCY4gPgXhkp3Aw0ZhqrjLNTQRzeoOPRwLtMktraID5ap6k4aI
23
- R0DAfqKqtdZFvMcyj+IVpqL0wE8CAwEAAaOBijCBhzAJBgNVHRMEAjAAMAsGA1Ud
24
- DwQEAwIEsDAdBgNVHQ4EFgQUo6GaGSMfYN0TFrof6GC6QT2GdMQwJgYDVR0RBB8w
25
- HYEbZ2VtbWFzdGVyQGphbWVzcm9iZXJ0c29uLmV1MCYGA1UdEgQfMB2BG2dlbW1h
26
- c3RlckBqYW1lc3JvYmVydHNvbi5ldTANBgkqhkiG9w0BAQUFAAOCAQEAOy2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3YNbStt+DHir1OfceK4JX3N7CiPnQsXTx06T3ZnUxiYUj0QquefTnqb/S7MO
24
+ XtAMy3eH5msr8cAYiPRBW0hr/6RGGDTMM6Cjz+VzFgAF6OXqVDN9bjYQqckCAwEA
25
+ AaOBijCBhzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQU/PN/KSth
26
+ nZ4pBrLLklzgnH00nkMwJgYDVR0RBB8wHYEbZ2VtbWFzdGVyQGphbWVzcm9iZXJ0
27
+ c29uLmV1MCYGA1UdEgQfMB2BG2dlbW1hc3RlckBqYW1lc3JvYmVydHNvbi5ldTAN
28
+ BgkqhkiG9w0BAQsFAAOCAYEAHM0WneD/luRLhn4hraEIWTNCUaVzz94DUcoo4umJ
29
+ 2APA5QsBXnnh33rUwCx3bWtTCR7mW0cShSVbGFwgvB7dRyegHczXlQcx2AgwB1k1
30
+ FzhR/37ef8Vdu44nXhhKj6NDhzVi89XuNLxSXzEHoGde6liAjTiGA7ydCyxSBdzq
31
+ Ld3WBJ+LycfVWgoNmW2csBCgrALXa145QKO5HW34n03wbZ5fAaCVy8GjAaHRf6Tf
32
+ 3QFe8+mYaXbHnqf2qEkNPIPQmdBKrfiyJK2kMIqQ3ldUGZZj+H5e1VOH8NKlSvr8
33
+ MtTHQ/vWwolPDjip3vyPbPMyNsdwC8QJHXiYl5M4rxYHSCaG6/+dMWMFAGMYVs52
34
+ 4LpA7DyCXsIeDLLZm4GvsGU+ntoCovwRCl4ZtgXtZt19QRze/nd9rcIxwULjVOBR
35
+ vmQbOdyo1gepCZyCN+UN/SCimjgu1yZtpI0S9lPHE1w/fMob3ohXflP/mnwUFxsN
36
+ KVwzt+QIecFrRei1GVykx8z3
33
37
  -----END CERTIFICATE-----
34
- date: 2015-09-24 00:00:00.000000000 Z
38
+ date: 2020-09-07 00:00:00.000000000 Z
35
39
  dependencies: []
36
40
  description:
37
- email: james@r0bertson.co.uk
41
+ email: james@jamesrobertson.eu
38
42
  executables: []
39
43
  extensions: []
40
44
  extra_rdoc_files: []
@@ -59,8 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
63
  - !ruby/object:Gem::Version
60
64
  version: '0'
61
65
  requirements: []
62
- rubyforge_project:
63
- rubygems_version: 2.4.8
66
+ rubygems_version: 3.0.3
64
67
  signing_key:
65
68
  specification_version: 4
66
69
  summary: A MyMedia FTP client which uses Net/FTP.
metadata.gz.sig CHANGED
Binary file