thecore_ftp_helpers 2.0.1 → 2.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/thecore_ftp_helpers.rb +21 -12
- data/lib/thecore_ftp_helpers/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 236e81e8ccdc89a2c890efb0cd85cc50017b15829bac2ba74449f654171cf176
|
4
|
+
data.tar.gz: 9cffb2f02a9bb90babe8ca03c9b8df4d4ce3097560a5a9430517587ec0be6074
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f3b8e73c55e8bd677e3370f83d3c6df899531325dbaa8eb0d3a457ba195ff316784cda1ef0585c5ada7d50536d1cfbb57afe3b6f41676dc6b4b68cd1ff6e336e
|
7
|
+
data.tar.gz: fd028abd521cf3f747b48d6b0243f545e07f33e02f5002cacba8a03e72139a683447af299673cb83ca2917d0dc273fb81f2f6b93596b8a0f3916eab576d7e5fc
|
data/lib/thecore_ftp_helpers.rb
CHANGED
@@ -11,30 +11,39 @@ module ThecoreFtpHelpers
|
|
11
11
|
puts "Connecting to FTP"
|
12
12
|
ftp = Net::FTP.open address, username, password
|
13
13
|
# ftp.passive = false
|
14
|
-
puts "Entering directory: #{directory}"
|
15
|
-
ftp.chdir(directory)
|
14
|
+
# puts "Entering directory: #{directory}"
|
15
|
+
# ftp.chdir(directory)
|
16
16
|
puts "Listing all files which respond to this pattern: #{pattern}"
|
17
17
|
begin
|
18
|
-
files = ftp.nlst(pattern)
|
18
|
+
# files = ftp.nlst(pattern)
|
19
|
+
files=ftp.mlsd directory
|
19
20
|
rescue => exception
|
20
21
|
# If we are here, maybe it's beacause of passive mode and the network too secure
|
21
22
|
# let's switch to active mode and try again
|
22
23
|
ftp.passive = false
|
23
|
-
files
|
24
|
+
files=ftp.mlsd directory
|
24
25
|
end
|
25
26
|
|
26
27
|
puts "Last import time: #{from.strftime('%Y-%m-%d %H:%M:%S.%N')}"
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
ftp.mtime(f).to_f > from.to_f
|
28
|
+
most_recent = nil
|
29
|
+
# puts "SELECTING FILES"
|
30
|
+
files = files.select {|f|
|
31
|
+
f.pathname.starts_with?(pattern) && f.modify.to_f > from.to_f
|
32
32
|
} unless from.blank?
|
33
|
-
puts "
|
34
|
-
most_recent = files.sort_by{|f|
|
33
|
+
# puts "SELECTED FILES: #{files.inspect}"
|
34
|
+
most_recent = files.sort_by{|f| f.modify.to_f}.last.pathname
|
35
|
+
# puts "MOST RECENT IS: #{most_recent}"
|
36
|
+
# files.select {|f|
|
37
|
+
# puts "For file: #{f}"
|
38
|
+
# puts "Filetime: #{ftp.mtime(f).strftime('%Y-%m-%d %H:%M:%S.%N')}"
|
39
|
+
# puts "File chosen? #{ftp.mtime(f).to_f > from.to_f}"
|
40
|
+
# ftp.mtime(f).to_f > from.to_f
|
41
|
+
# } unless from.blank?
|
42
|
+
# puts "Chosen files: #{files.inspect}"
|
43
|
+
# most_recent = files.sort_by{|f| ftp.mtime(f).to_f}.last
|
35
44
|
puts "Opening File: #{most_recent || "No file has been chosen."}"
|
36
45
|
ftp.close if close
|
37
|
-
[most_recent, ftp]
|
46
|
+
["#{directory}/#{most_recent}", ftp]
|
38
47
|
end
|
39
48
|
|
40
49
|
# If destination is nil, the file will just be downloaded to RAM
|