mymedia_ftp 0.1.1 → 0.3.2
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 +181 -30
- metadata +27 -24
- 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: 70b64854b4af1689d9c02b6db9af47760a956c428630a05ab9681fcb109a8e33
|
4
|
+
data.tar.gz: 7e216ea42a4aa8635f31ea0d0bdd63e3efd25ba743e53b8c5d8623967dfeffbe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ba16fcace08fd38a254afefcd4f97eda8b8a14914873ab24ab5deb29c007c6498edb59d4296302642f539761a503893eb8c57a473f9c5df3880874fa52b6106
|
7
|
+
data.tar.gz: 0563b8523d8050a66dd683a0ea390c9f25cebfe9650471eec542f121a6cacb611a8de55ec5a319f7dbf8b7aa1c52fb368f7c4856dd7c78692da39d0ed61474c6
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/mymedia_ftp.rb
CHANGED
@@ -3,62 +3,213 @@
|
|
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',
|
61
|
+
port: 21, debug: false)
|
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
|
+
|
73
|
+
@debug = debug
|
12
74
|
|
13
|
-
@curdir =
|
75
|
+
@curdir = '/'
|
14
76
|
super()
|
15
77
|
connect(host, port)
|
16
78
|
login(user, password)
|
17
79
|
|
18
80
|
end
|
81
|
+
|
82
|
+
def chdir(dir)
|
83
|
+
super(dir)
|
84
|
+
@curdir = pwd
|
85
|
+
end
|
86
|
+
|
87
|
+
alias cd chdir
|
19
88
|
|
20
|
-
def cp(src='', dest='')
|
89
|
+
def cp(src='', dest='', direction=:inbound, &blk)
|
21
90
|
|
91
|
+
return outbound_cp(src, dest) if direction == :outbound
|
92
|
+
|
93
|
+
puts 'cp: ' + src.inspect if @debug
|
22
94
|
chdir File.dirname(src)
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
95
|
+
dir = File.dirname(dest)
|
96
|
+
FileUtils.mkdir_p dir
|
97
|
+
Dir.chdir dir
|
98
|
+
|
99
|
+
puts 'copying ...' if @debug
|
100
|
+
|
101
|
+
files = if src =~ /[\*\?]/ then
|
102
|
+
|
103
|
+
cp_files(src)
|
104
|
+
|
105
|
+
else
|
106
|
+
|
107
|
+
begin
|
108
|
+
getbinaryfile src, dest
|
109
|
+
rescue Net::FTPPermError => e
|
110
|
+
puts 'e: ' + e.inspect
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
29
114
|
|
30
|
-
|
115
|
+
end
|
116
|
+
|
117
|
+
def delete(filename)
|
118
|
+
super(filename)
|
119
|
+
'file deleted'
|
120
|
+
end
|
121
|
+
|
122
|
+
def list_filenames(s=@curdir+'/*')
|
123
|
+
|
124
|
+
if @debug
|
125
|
+
puts 'inside list_filenames'
|
126
|
+
puts 's: ' + s.inspect
|
127
|
+
end
|
128
|
+
|
129
|
+
if s =~ /\*/ then
|
130
|
+
|
131
|
+
src = File.dirname(s)
|
132
|
+
|
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
|
31
141
|
|
32
|
-
|
33
|
-
|
34
|
-
|
142
|
+
list(src).inject([]) do |r, x|
|
143
|
+
|
144
|
+
raw_attr, _, owner, group, filesize, month, day, time, filename = \
|
145
|
+
x.split(/ +/,9)
|
146
|
+
type = raw_attr =~ /d/ ? :directory : :file
|
147
|
+
|
148
|
+
if q then
|
149
|
+
filename[/^#{q}$/] ? r << {name: filename, type: type} : r
|
150
|
+
else
|
151
|
+
r << {name: filename, type: type}
|
152
|
+
end
|
153
|
+
r
|
35
154
|
end
|
36
155
|
|
37
156
|
end
|
38
|
-
|
157
|
+
|
158
|
+
alias ls list_filenames
|
39
159
|
|
40
160
|
def mv(src='', dest='')
|
41
161
|
|
42
162
|
puts 'moving ...'
|
43
|
-
cp(src, dest)
|
44
|
-
|
163
|
+
cp(src, dest) do |file, type|
|
164
|
+
type == :file ? delete(file) : rmdir(file)
|
165
|
+
end
|
45
166
|
|
46
167
|
end
|
47
|
-
|
168
|
+
|
169
|
+
alias rm delete
|
170
|
+
|
48
171
|
private
|
49
|
-
|
50
|
-
def
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
172
|
+
|
173
|
+
def cp_dir(directory, &blk)
|
174
|
+
|
175
|
+
puts 'inside cp_dir: ' + directory.inspect if @debug
|
176
|
+
FileUtils.mkdir_p directory
|
177
|
+
parent_dir = pwd
|
178
|
+
chdir directory
|
179
|
+
cp('*', directory, &blk)
|
180
|
+
chdir parent_dir
|
181
|
+
end
|
182
|
+
|
183
|
+
def cp_files(src)
|
184
|
+
|
185
|
+
files = list_filenames(src)
|
186
|
+
|
187
|
+
files.each do |h|
|
188
|
+
|
189
|
+
name, type = h[:name], h[:type]
|
190
|
+
|
191
|
+
puts name
|
192
|
+
|
193
|
+
if type == :file then
|
194
|
+
begin
|
195
|
+
getbinaryfile name, name.downcase.gsub(/ +/,'-')
|
196
|
+
rescue Net::FTPPermError => e
|
197
|
+
puts 'e: ' + e.inspect
|
198
|
+
end
|
199
|
+
else
|
200
|
+
cp_dir(name, &blk)
|
201
|
+
end
|
202
|
+
blk.call(name, type) if block_given?
|
203
|
+
end
|
62
204
|
end
|
63
205
|
|
206
|
+
def outbound_cp(src, destination='.')
|
207
|
+
|
208
|
+
if File.basename(destination) == '.' then
|
209
|
+
destination.sub!(/\.$/, File.basename(src))
|
210
|
+
end
|
211
|
+
|
212
|
+
putbinaryfile(src, destination)
|
213
|
+
end
|
214
|
+
|
64
215
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -10,28 +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
|
-
|
32
|
-
|
13
|
+
MIIEXjCCAsagAwIBAgIBATANBgkqhkiG9w0BAQsFADAsMSowKAYDVQQDDCFnZW1t
|
14
|
+
YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMjAwOTA2MTA1OTAxWhcN
|
15
|
+
MjEwOTA2MTA1OTAxWjAsMSowKAYDVQQDDCFnZW1tYXN0ZXIvREM9amFtZ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DhzVi89XuNLxSXzEHoGde6liAjTiGA7ydCyxSBdzq
|
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:
|
38
|
+
date: 2020-09-12 00:00:00.000000000 Z
|
35
39
|
dependencies: []
|
36
40
|
description:
|
37
41
|
email: james@jamesrobertson.eu
|
@@ -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
|
-
|
63
|
-
rubygems_version: 2.6.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
|