mymedia_ftp 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/mymedia_ftp.rb +95 -27
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e8e7b10bc85f00e03c740ffeaa1d437ad5c16df06f21668416e8a1241c3d735
|
4
|
+
data.tar.gz: fd83e3ce6fae0b9036b1829afee8ab873babc453600a478a5c95ec2a43860af2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd889589d614b195a4a5c9cf03dfba5c8c927a513efa7b713451d9f4fc0e0a824310c4f7c97e03cd00e109f522b8521c9fa4c9432a56d3c1006aa2b199159fd3
|
7
|
+
data.tar.gz: 7534ec99cce8d55d5d19632b101fdb056a50ff780c4a4cbdbce00ebde11122dfc0cc14913f249669257ddf6778f5855a17dc47ae4113ecbeca7382b39cddc160
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/mymedia_ftp.rb
CHANGED
@@ -3,11 +3,51 @@
|
|
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
|
|
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
|
+
new(uri, debug: debug).ls(remotepath)
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.read(s, debug: false)
|
32
|
+
|
33
|
+
uri, remotepath = s.match(/^(ftp:\/\/[^\/]+)(\/[^$]+)/).captures
|
34
|
+
ftp = new(uri, debug: debug)
|
35
|
+
p ftp if debug
|
36
|
+
|
37
|
+
tmpfile = Tempfile.new('ftp')
|
38
|
+
|
39
|
+
ftp.cp remotepath, tmpfile.path
|
40
|
+
File.read tmpfile.path
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.rm(s, debug: false)
|
45
|
+
|
46
|
+
uri, remotepath = s.match(/^(ftp:\/\/[^\/]+)(\/[^$]+)/).captures
|
47
|
+
new(uri, debug: debug).rm(remotepath)
|
48
|
+
|
49
|
+
end
|
50
|
+
|
11
51
|
def initialize(s=nil, host: '127.0.0.1', user: 'user', password: '1234',
|
12
52
|
port: 21, debug: false)
|
13
53
|
|
@@ -43,29 +83,24 @@ class MyMediaFTP < Net::FTP
|
|
43
83
|
|
44
84
|
puts 'cp: ' + src.inspect if @debug
|
45
85
|
chdir File.dirname(src)
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
files = list_filenames(src)
|
86
|
+
dir = File.dirname(dest)
|
87
|
+
FileUtils.mkdir_p dir
|
88
|
+
Dir.chdir dir
|
50
89
|
|
51
|
-
puts 'copying ...'
|
52
|
-
|
53
|
-
files
|
54
|
-
|
55
|
-
|
90
|
+
puts 'copying ...' if @debug
|
91
|
+
|
92
|
+
files = if src =~ /[\*\?]/ then
|
93
|
+
|
94
|
+
cp_files(src)
|
56
95
|
|
57
|
-
|
96
|
+
else
|
97
|
+
|
98
|
+
begin
|
99
|
+
getbinaryfile src, dest
|
100
|
+
rescue Net::FTPPermError => e
|
101
|
+
puts 'e: ' + e.inspect
|
102
|
+
end
|
58
103
|
|
59
|
-
if type == :file then
|
60
|
-
begin
|
61
|
-
getbinaryfile name, name.downcase.gsub(/ +/,'-')
|
62
|
-
rescue Net::FTPPermError => e
|
63
|
-
puts 'e: ' + e.inspect
|
64
|
-
end
|
65
|
-
else
|
66
|
-
cp_dir(name, &blk)
|
67
|
-
end
|
68
|
-
blk.call(name, type) if block_given?
|
69
104
|
end
|
70
105
|
|
71
106
|
end
|
@@ -82,20 +117,30 @@ class MyMediaFTP < Net::FTP
|
|
82
117
|
puts 's: ' + s.inspect
|
83
118
|
end
|
84
119
|
|
85
|
-
|
120
|
+
if s =~ /\*/ then
|
121
|
+
|
122
|
+
src = File.dirname(s)
|
86
123
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
124
|
+
raw_q = File.basename(s)
|
125
|
+
puts 'raw_q: ' + raw_q.inspect if @debug
|
126
|
+
|
127
|
+
q = raw_q.gsub('.','\.').gsub('*','.*').gsub('?','.?')\
|
128
|
+
.sub(/[^\*\?\.]$/,'.*')
|
129
|
+
else
|
130
|
+
src = s
|
131
|
+
end
|
92
132
|
|
93
133
|
list(src).inject([]) do |r, x|
|
94
134
|
|
95
135
|
raw_attr, _, owner, group, filesize, month, day, time, filename = \
|
96
136
|
x.split(/ +/,9)
|
97
137
|
type = raw_attr =~ /d/ ? :directory : :file
|
98
|
-
|
138
|
+
|
139
|
+
if q then
|
140
|
+
filename[/^#{q}$/] ? r << {name: filename, type: type} : r
|
141
|
+
else
|
142
|
+
r << {name: filename, type: type}
|
143
|
+
end
|
99
144
|
r
|
100
145
|
end
|
101
146
|
|
@@ -126,6 +171,29 @@ class MyMediaFTP < Net::FTP
|
|
126
171
|
chdir parent_dir
|
127
172
|
end
|
128
173
|
|
174
|
+
def cp_files(src)
|
175
|
+
|
176
|
+
files = list_filenames(src)
|
177
|
+
|
178
|
+
files.each do |h|
|
179
|
+
|
180
|
+
name, type = h[:name], h[:type]
|
181
|
+
|
182
|
+
puts name
|
183
|
+
|
184
|
+
if type == :file then
|
185
|
+
begin
|
186
|
+
getbinaryfile name, name.downcase.gsub(/ +/,'-')
|
187
|
+
rescue Net::FTPPermError => e
|
188
|
+
puts 'e: ' + e.inspect
|
189
|
+
end
|
190
|
+
else
|
191
|
+
cp_dir(name, &blk)
|
192
|
+
end
|
193
|
+
blk.call(name, type) if block_given?
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
129
197
|
def outbound_cp(src, destination='.')
|
130
198
|
|
131
199
|
if File.basename(destination) == '.' then
|
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.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -35,7 +35,7 @@ cert_chain:
|
|
35
35
|
vmQbOdyo1gepCZyCN+UN/SCimjgu1yZtpI0S9lPHE1w/fMob3ohXflP/mnwUFxsN
|
36
36
|
KVwzt+QIecFrRei1GVykx8z3
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date: 2020-09-
|
38
|
+
date: 2020-09-07 00:00:00.000000000 Z
|
39
39
|
dependencies: []
|
40
40
|
description:
|
41
41
|
email: james@jamesrobertson.eu
|
metadata.gz.sig
CHANGED
Binary file
|