mymedia_ftp 0.2.0 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/mymedia_ftp.rb +140 -27
- metadata +27 -23
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b7eb16a509a0458ad7e202999d535cb7aabe305e08b5267ae0f39f3583ffeecd
|
4
|
+
data.tar.gz: 4c0f913a18c5a00fc91c6a4be31895fcbdd265f47382b66fce04ecba22d7b05c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5cd0981666fe7fd3434a601d80698d774972706743503e1d5300fe0c94da5ab6b84816ec141f5b61f2464f38c6bbd3f8c5a10d0ab5fba58fa29009cec5dce640
|
7
|
+
data.tar.gz: b4b03d2487ac64c1d571f51ec11886e70adbe943c1f6111be4cff7a9e2ded7b797c84adfcb86e74af9c3925500a38feacc2a683019a56a2c0ff58907a7837066
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/mymedia_ftp.rb
CHANGED
@@ -3,15 +3,75 @@
|
|
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
|
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.inspect 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 self.write(s, content='', debug: false)
|
53
|
+
|
54
|
+
tmpfile = Tempfile.new('ftp')
|
55
|
+
File.write tmpfile.path, content
|
56
|
+
self.cp tmpfile.path, s
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
def initialize(s=nil, host: '127.0.0.1', user: 'user', password: '1234',
|
12
61
|
port: 21, debug: false)
|
13
62
|
|
63
|
+
if s then
|
64
|
+
|
65
|
+
r = s.match(/(?<user>\w+):(?<password>\w+)@(?<host>[^:]+)(?:\:(?<port>\d+))?/)
|
66
|
+
h = r.named_captures.map {|k,v| [k.to_sym, v]}.to_h
|
67
|
+
puts 'h: ' + h.inspect if debug
|
68
|
+
user, password, host = h.values.take(3)
|
69
|
+
port = h[:port] if h[:port]
|
70
|
+
|
71
|
+
end
|
72
|
+
|
14
73
|
@debug = debug
|
74
|
+
|
15
75
|
@curdir = '/'
|
16
76
|
super()
|
17
77
|
connect(host, port)
|
@@ -23,55 +83,74 @@ class MyMediaFTP < Net::FTP
|
|
23
83
|
super(dir)
|
24
84
|
@curdir = pwd
|
25
85
|
end
|
86
|
+
|
87
|
+
alias cd chdir
|
26
88
|
|
27
|
-
def cp(src='', dest='', &blk)
|
89
|
+
def cp(src='', dest='', direction=:inbound, &blk)
|
28
90
|
|
91
|
+
return outbound_cp(src, dest) if direction == :outbound
|
92
|
+
|
29
93
|
puts 'cp: ' + src.inspect if @debug
|
30
94
|
chdir File.dirname(src)
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
files = list_filenames(src)
|
35
|
-
|
36
|
-
puts 'copying ...'
|
95
|
+
dir = File.dirname(dest)
|
96
|
+
FileUtils.mkdir_p dir
|
97
|
+
Dir.chdir dir
|
37
98
|
|
38
|
-
|
39
|
-
|
40
|
-
|
99
|
+
puts 'copying ...' if @debug
|
100
|
+
|
101
|
+
files = if src =~ /[\*\?]/ then
|
102
|
+
|
103
|
+
cp_files(src)
|
41
104
|
|
42
|
-
|
105
|
+
else
|
106
|
+
|
107
|
+
begin
|
108
|
+
getbinaryfile src, dest
|
109
|
+
rescue Net::FTPPermError => e
|
110
|
+
puts 'e: ' + e.inspect
|
111
|
+
end
|
43
112
|
|
44
|
-
if type == :file then
|
45
|
-
getbinaryfile name, name.downcase.gsub(/ +/,'-')
|
46
|
-
else
|
47
|
-
cp_dir(name, &blk)
|
48
|
-
end
|
49
|
-
blk.call(name, type) if block_given?
|
50
113
|
end
|
51
114
|
|
52
115
|
end
|
53
116
|
|
54
|
-
def
|
117
|
+
def delete(filename)
|
118
|
+
super(filename)
|
119
|
+
'file deleted'
|
120
|
+
end
|
121
|
+
|
122
|
+
def list_filenames(s=@curdir+'/*', ctimesort: false)
|
55
123
|
|
56
124
|
if @debug
|
57
125
|
puts 'inside list_filenames'
|
58
126
|
puts 's: ' + s.inspect
|
59
127
|
end
|
60
128
|
|
61
|
-
|
129
|
+
if s =~ /\*/ then
|
130
|
+
|
131
|
+
src = File.dirname(s)
|
62
132
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
133
|
+
raw_q = File.basename(s)
|
134
|
+
puts 'raw_q: ' + raw_q.inspect if @debug
|
135
|
+
|
136
|
+
q = raw_q.gsub('.','\.').gsub('*','.*').gsub('?','.?')\
|
137
|
+
.sub(/[^\*\?\.]$/,'.*')
|
138
|
+
else
|
139
|
+
src = s
|
140
|
+
end
|
68
141
|
|
69
142
|
list(src).inject([]) do |r, x|
|
70
143
|
|
71
144
|
raw_attr, _, owner, group, filesize, month, day, time, filename = \
|
72
145
|
x.split(/ +/,9)
|
73
|
-
type = raw_attr
|
74
|
-
|
146
|
+
type = raw_attr[0] == 'd' ? :directory : :file
|
147
|
+
d = Time.parse([Date.today.year, month, day, time].join(' ') )
|
148
|
+
|
149
|
+
if q then
|
150
|
+
filename[/^#{q}$/] ? r << {name: filename, type: type, filesize: filesize, ctime: d} : r
|
151
|
+
else
|
152
|
+
r << {name: filename, type: type, filesize: filesize, ctime: d}
|
153
|
+
end
|
75
154
|
r
|
76
155
|
end
|
77
156
|
|
@@ -88,6 +167,8 @@ class MyMediaFTP < Net::FTP
|
|
88
167
|
|
89
168
|
end
|
90
169
|
|
170
|
+
alias rm delete
|
171
|
+
|
91
172
|
private
|
92
173
|
|
93
174
|
def cp_dir(directory, &blk)
|
@@ -99,5 +180,37 @@ class MyMediaFTP < Net::FTP
|
|
99
180
|
cp('*', directory, &blk)
|
100
181
|
chdir parent_dir
|
101
182
|
end
|
183
|
+
|
184
|
+
def cp_files(src)
|
185
|
+
|
186
|
+
files = list_filenames(src)
|
187
|
+
|
188
|
+
files.each do |h|
|
189
|
+
|
190
|
+
name, type = h[:name], h[:type]
|
191
|
+
|
192
|
+
puts name
|
193
|
+
|
194
|
+
if type == :file then
|
195
|
+
begin
|
196
|
+
getbinaryfile name, name.downcase.gsub(/ +/,'-')
|
197
|
+
rescue Net::FTPPermError => e
|
198
|
+
puts 'e: ' + e.inspect
|
199
|
+
end
|
200
|
+
else
|
201
|
+
cp_dir(name, &blk)
|
202
|
+
end
|
203
|
+
blk.call(name, type) if block_given?
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
def outbound_cp(src, destination='.')
|
208
|
+
|
209
|
+
if File.basename(destination) == '.' then
|
210
|
+
destination.sub!(/\.$/, File.basename(src))
|
211
|
+
end
|
212
|
+
|
213
|
+
putbinaryfile(src, destination)
|
214
|
+
end
|
102
215
|
|
103
216
|
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.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -10,27 +10,32 @@ bindir: bin
|
|
10
10
|
cert_chain:
|
11
11
|
- |
|
12
12
|
-----BEGIN CERTIFICATE-----
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
13
|
+
MIIEXjCCAsagAwIBAgIBATANBgkqhkiG9w0BAQsFADAsMSowKAYDVQQDDCFnZW1t
|
14
|
+
YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMjAwOTA2MTA1OTAxWhcN
|
15
|
+
MjEwOTA2MTA1OTAxWjAsMSowKAYDVQQDDCFnZW1tYXN0ZXIvREM9amFtZXNyb2Jl
|
16
|
+
cnRzb24vREM9ZXUwggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAwggGKA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csBCgrALXa145QKO5HW34n03wbZ5fAaCVy8GjAaHRf6Tf
|
32
|
+
3QFe8+mYaXbHnqf2qEkNPIPQmdBKrfiyJK2kMIqQ3ldUGZZj+H5e1VOH8NKlSvr8
|
33
|
+
MtTHQ/vWwolPDjip3vyPbPMyNsdwC8QJHXiYl5M4rxYHSCaG6/+dMWMFAGMYVs52
|
34
|
+
4LpA7DyCXsIeDLLZm4GvsGU+ntoCovwRCl4ZtgXtZt19QRze/nd9rcIxwULjVOBR
|
35
|
+
vmQbOdyo1gepCZyCN+UN/SCimjgu1yZtpI0S9lPHE1w/fMob3ohXflP/mnwUFxsN
|
36
|
+
KVwzt+QIecFrRei1GVykx8z3
|
32
37
|
-----END CERTIFICATE-----
|
33
|
-
date:
|
38
|
+
date: 2020-10-16 00:00:00.000000000 Z
|
34
39
|
dependencies: []
|
35
40
|
description:
|
36
41
|
email: james@jamesrobertson.eu
|
@@ -58,8 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
58
63
|
- !ruby/object:Gem::Version
|
59
64
|
version: '0'
|
60
65
|
requirements: []
|
61
|
-
|
62
|
-
rubygems_version: 2.6.13
|
66
|
+
rubygems_version: 3.0.3
|
63
67
|
signing_key:
|
64
68
|
specification_version: 4
|
65
69
|
summary: A MyMedia FTP client which uses Net/FTP.
|
metadata.gz.sig
CHANGED
Binary file
|