ftp_paradise 1.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.md +319 -0
- data/bin/create_remote_directory +9 -0
- data/bin/ftp_get +17 -0
- data/bin/ftp_gtk3 +7 -0
- data/bin/ftp_upload +42 -0
- data/bin/ftp_upload_binary +18 -0
- data/bin/iftp +7 -0
- data/bin/remote_remove +28 -0
- data/doc/README.gen +302 -0
- data/doc/todo/TODO_FOR_FTP_PARADISE_PROJECT.md +79 -0
- data/ftp_paradise.gemspec +122 -0
- data/lib/ftp_paradise.rb +5 -0
- data/lib/ftp_paradise/base/cliner.rb +23 -0
- data/lib/ftp_paradise/base/colours.rb +83 -0
- data/lib/ftp_paradise/base/prototype.rb +171 -0
- data/lib/ftp_paradise/base/reset.rb +29 -0
- data/lib/ftp_paradise/colours/colours.rb +141 -0
- data/lib/ftp_paradise/colours/use_colours.rb +76 -0
- data/lib/ftp_paradise/configuration/configuration.rb +49 -0
- data/lib/ftp_paradise/connection/README.md +1 -0
- data/lib/ftp_paradise/connection/connection.rb +35 -0
- data/lib/ftp_paradise/connection/constants.rb +46 -0
- data/lib/ftp_paradise/connection/data.rb +164 -0
- data/lib/ftp_paradise/connection/debug.rb +78 -0
- data/lib/ftp_paradise/connection/directory_handling.rb +271 -0
- data/lib/ftp_paradise/connection/do_login.rb +108 -0
- data/lib/ftp_paradise/connection/download.rb +86 -0
- data/lib/ftp_paradise/connection/file_handling.rb +174 -0
- data/lib/ftp_paradise/connection/ftp_object.rb +21 -0
- data/lib/ftp_paradise/connection/initialize.rb +88 -0
- data/lib/ftp_paradise/connection/initialize_a_new_net_ftp_object_with_this_url.rb +20 -0
- data/lib/ftp_paradise/connection/is_connected.rb +46 -0
- data/lib/ftp_paradise/connection/misc.rb +474 -0
- data/lib/ftp_paradise/connection/notify.rb +71 -0
- data/lib/ftp_paradise/connection/password.rb +47 -0
- data/lib/ftp_paradise/connection/port.rb +33 -0
- data/lib/ftp_paradise/connection/remote_pwd.rb +72 -0
- data/lib/ftp_paradise/connection/remote_url.rb +164 -0
- data/lib/ftp_paradise/connection/remove.rb +143 -0
- data/lib/ftp_paradise/connection/reset.rb +78 -0
- data/lib/ftp_paradise/connection/run.rb +18 -0
- data/lib/ftp_paradise/connection/set_array_available_hosts.rb +27 -0
- data/lib/ftp_paradise/connection/set_input.rb +18 -0
- data/lib/ftp_paradise/connection/show.rb +153 -0
- data/lib/ftp_paradise/connection/sync_ftp_object_onto_the_main_namespace.rb +24 -0
- data/lib/ftp_paradise/connection/transfer_mode.rb +163 -0
- data/lib/ftp_paradise/connection/upload.rb +253 -0
- data/lib/ftp_paradise/connection/use_default_dataset.rb +40 -0
- data/lib/ftp_paradise/connection/username.rb +42 -0
- data/lib/ftp_paradise/constants/constants.rb +19 -0
- data/lib/ftp_paradise/constants/misc.rb +57 -0
- data/lib/ftp_paradise/constants/namespace.rb +14 -0
- data/lib/ftp_paradise/constants/newline.rb +14 -0
- data/lib/ftp_paradise/constants/roebe.rb +31 -0
- data/lib/ftp_paradise/constants/roebe_ftp_constants.rb +233 -0
- data/lib/ftp_paradise/entry/entry.rb +300 -0
- data/lib/ftp_paradise/gui/gtk2/ftp_paradise.rb +34 -0
- data/lib/ftp_paradise/gui/gtk3/ftp_paradise.rb +34 -0
- data/lib/ftp_paradise/gui/shared_code/ftp_paradise/ftp_paradise_module.rb +709 -0
- data/lib/ftp_paradise/images/connection_image.png +0 -0
- data/lib/ftp_paradise/interactive_ftp/constants.rb +103 -0
- data/lib/ftp_paradise/interactive_ftp/directory_handling.rb +216 -0
- data/lib/ftp_paradise/interactive_ftp/help.rb +50 -0
- data/lib/ftp_paradise/interactive_ftp/initialize.rb +27 -0
- data/lib/ftp_paradise/interactive_ftp/interactive_ftp.rb +998 -0
- data/lib/ftp_paradise/interactive_ftp/main_loop.rb +51 -0
- data/lib/ftp_paradise/interactive_ftp/menu.rb +786 -0
- data/lib/ftp_paradise/interactive_ftp/misc.rb +208 -0
- data/lib/ftp_paradise/interactive_ftp/mode.rb +124 -0
- data/lib/ftp_paradise/interactive_ftp/readline.rb +113 -0
- data/lib/ftp_paradise/interactive_ftp/remove.rb +97 -0
- data/lib/ftp_paradise/interactive_ftp/reset.rb +90 -0
- data/lib/ftp_paradise/interactive_ftp/run.rb +22 -0
- data/lib/ftp_paradise/interactive_ftp/show.rb +184 -0
- data/lib/ftp_paradise/interactive_ftp/upload.rb +90 -0
- data/lib/ftp_paradise/interactive_ftp/user_input.rb +53 -0
- data/lib/ftp_paradise/project/project.rb +64 -0
- data/lib/ftp_paradise/requires/common_basic_requires.rb +14 -0
- data/lib/ftp_paradise/requires/common_external_requires.rb +9 -0
- data/lib/ftp_paradise/requires/require_the_constants.rb +7 -0
- data/lib/ftp_paradise/requires/require_the_ftp_paradise_project.rb +18 -0
- data/lib/ftp_paradise/requires/require_the_ftp_paradise_project_with_the_GUI_bindings.rb +10 -0
- data/lib/ftp_paradise/requires/require_the_toplevel_methods.rb +24 -0
- data/lib/ftp_paradise/toplevel_methods/can_connect_to_remote_site.rb +28 -0
- data/lib/ftp_paradise/toplevel_methods/clear_user_dataset.rb +28 -0
- data/lib/ftp_paradise/toplevel_methods/connect.rb +50 -0
- data/lib/ftp_paradise/toplevel_methods/data.rb +31 -0
- data/lib/ftp_paradise/toplevel_methods/determine_user_dataset_from_this_hash.rb +37 -0
- data/lib/ftp_paradise/toplevel_methods/directory_related_actions.rb +33 -0
- data/lib/ftp_paradise/toplevel_methods/e.rb +16 -0
- data/lib/ftp_paradise/toplevel_methods/file_related_actions.rb +49 -0
- data/lib/ftp_paradise/toplevel_methods/ftp_object.rb +270 -0
- data/lib/ftp_paradise/toplevel_methods/is_on_roebe.rb +20 -0
- data/lib/ftp_paradise/toplevel_methods/login_name.rb +49 -0
- data/lib/ftp_paradise/toplevel_methods/misc.rb +16 -0
- data/lib/ftp_paradise/toplevel_methods/opn.rb +24 -0
- data/lib/ftp_paradise/toplevel_methods/password.rb +50 -0
- data/lib/ftp_paradise/toplevel_methods/port.rb +41 -0
- data/lib/ftp_paradise/toplevel_methods/rds.rb +18 -0
- data/lib/ftp_paradise/toplevel_methods/remote_url.rb +57 -0
- data/lib/ftp_paradise/toplevel_methods/time.rb +45 -0
- data/lib/ftp_paradise/toplevel_methods/upload_and_download.rb +108 -0
- data/lib/ftp_paradise/version/version.rb +19 -0
- data/lib/ftp_paradise/www/public/css/style.css +3 -0
- data/lib/ftp_paradise/www/sinatra_web_interface.rb +242 -0
- data/lib/ftp_paradise/www/views/index.slim +3 -0
- data/lib/ftp_paradise/www/views/layout.slim +11 -0
- data/lib/ftp_paradise/www/web_interface.cgi +34 -0
- data/lib/ftp_paradise/yaml/automatically_connect_on_startup_of_the_interactive_ftp_shell.yml +1 -0
- data/lib/ftp_paradise/yaml/debug.yml +1 -0
- data/lib/ftp_paradise/yaml/open_in_default_editor.yml +1 -0
- data/lib/ftp_paradise/yaml/show_full_names.yml +1 -0
- data/lib/ftp_paradise/yaml/use_colours.yml +1 -0
- data/test/testing_ftp_paradise.rb +94 -0
- data/test/testing_minimal_pure_net_ftp_example_to_connect.rb +28 -0
- data/test/testing_the_ftp_connection_component.rb +70 -0
- data/test/testing_upload_a_local_directory.rb +10 -0
- metadata +336 -0
@@ -0,0 +1,31 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'ftp_paradise/constants/roebe.rb'
|
6
|
+
# FILE_ROEBE_FTP
|
7
|
+
# HOME_DIRECTOY_OF_USER_X
|
8
|
+
# =========================================================================== #
|
9
|
+
module FtpParadise
|
10
|
+
|
11
|
+
# =========================================================================== #
|
12
|
+
# === HOME_DIRECTORY_OF_USER_X
|
13
|
+
#
|
14
|
+
# This is also only useful on my home setup.
|
15
|
+
# =========================================================================== #
|
16
|
+
HOME_DIRECTORY_OF_USER_X = '/home/x/'
|
17
|
+
|
18
|
+
# =========================================================================== #
|
19
|
+
# === FILE_ROEBE_FTP
|
20
|
+
#
|
21
|
+
# In theory you could change this if you use a similar .yml file.
|
22
|
+
#
|
23
|
+
# This will, on my home directory, expand to:
|
24
|
+
#
|
25
|
+
# /home/x/DATA/PC/OS/LINUX/FTP/YAML/roebe_ftp.yml
|
26
|
+
#
|
27
|
+
# =========================================================================== #
|
28
|
+
FILE_ROEBE_FTP =
|
29
|
+
"#{HOME_DIRECTORY_OF_USER_X}DATA/PC/OS/LINUX/FTP/YAML/roebe_ftp.yml"
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,233 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'ftp_paradise/constants/roebe_ftp_constants.rb'
|
6
|
+
# include FtpParadise::RoebeFtpConstants
|
7
|
+
# =========================================================================== #
|
8
|
+
module FtpParadise # === FtpParadise::RoebeFtpConstants
|
9
|
+
|
10
|
+
module RoebeFtpConstants
|
11
|
+
|
12
|
+
require 'ftp_paradise/constants/roebe.rb'
|
13
|
+
require 'yaml'
|
14
|
+
|
15
|
+
# ========================================================================= #
|
16
|
+
# === FtpParadise::RoebeFtpConstants::@hash_ftp_dataset
|
17
|
+
# ========================================================================= #
|
18
|
+
@hash_ftp_dataset = {}
|
19
|
+
|
20
|
+
# ========================================================================= #
|
21
|
+
# === FTP_DATASET
|
22
|
+
#
|
23
|
+
# Here we will load my custom ftp file, but only if this file exists.
|
24
|
+
#
|
25
|
+
# If it does not exist, then we will not load it, and we will not
|
26
|
+
# make use of it. That way others can ignore this file altogether.
|
27
|
+
#
|
28
|
+
# The location for my file is at:
|
29
|
+
#
|
30
|
+
# bl $MY_FTP/YAML/roebe_ftp.yml
|
31
|
+
#
|
32
|
+
# ========================================================================= #
|
33
|
+
if File.exist? FILE_ROEBE_FTP
|
34
|
+
FTP_DATASET = FILE_ROEBE_FTP
|
35
|
+
else
|
36
|
+
begin
|
37
|
+
home_dir = File.expand_path('~')
|
38
|
+
rescue; end
|
39
|
+
home_dir = '/root' if home_dir.nil? # A safeguard here if ENV is unavailable.
|
40
|
+
FTP_DATASET = "#{home_dir}/roebe_ftp.yml"
|
41
|
+
end
|
42
|
+
|
43
|
+
# ========================================================================= #
|
44
|
+
# === FtpParadise::RoebeFtpConstants.file?
|
45
|
+
#
|
46
|
+
# Feedback where that file is.
|
47
|
+
# ========================================================================= #
|
48
|
+
def self.file?
|
49
|
+
FILE_ROEBE_FTP
|
50
|
+
end
|
51
|
+
|
52
|
+
# ========================================================================= #
|
53
|
+
# === FtpParadise::RoebeFtpConstants.hash_ftp_dataset?
|
54
|
+
# ========================================================================= #
|
55
|
+
def self.hash_ftp_dataset?
|
56
|
+
@hash_ftp_dataset
|
57
|
+
end; self.instance_eval { alias hash? hash_ftp_dataset? } # === FtpParadise::RoebeFtpConstants.hash_ftp_dataset?.hash?
|
58
|
+
|
59
|
+
# ========================================================================= #
|
60
|
+
# Next check whether the roebe_ftp.yml file exists. If it does then
|
61
|
+
# we will load it up.
|
62
|
+
# ========================================================================= #
|
63
|
+
if File.exist? file?
|
64
|
+
dataset = YAML.load_file(file?)
|
65
|
+
@hash_ftp_dataset.update(dataset) # Sync the dataset.
|
66
|
+
# ======================================================================= #
|
67
|
+
# The format of the dataset has to be uniform. We start with the
|
68
|
+
# remote URL, then the user name, the password, and then the port.
|
69
|
+
# ======================================================================= #
|
70
|
+
|
71
|
+
# ======================================================================= #
|
72
|
+
# === A1 TAG
|
73
|
+
# ======================================================================= #
|
74
|
+
_ = dataset['a1']
|
75
|
+
A1 = [
|
76
|
+
_['url'],
|
77
|
+
_['user_name'],
|
78
|
+
_['password'],
|
79
|
+
_['port']
|
80
|
+
]
|
81
|
+
|
82
|
+
# ======================================================================= #
|
83
|
+
# === ZYMIX TAG
|
84
|
+
# ======================================================================= #
|
85
|
+
_ = dataset['zymix']
|
86
|
+
ZYMIX = [
|
87
|
+
_['url'],
|
88
|
+
_['user_name'],
|
89
|
+
_['password'],
|
90
|
+
_['port']
|
91
|
+
]
|
92
|
+
|
93
|
+
# ======================================================================= #
|
94
|
+
# === Bytehost Tag
|
95
|
+
#
|
96
|
+
# bl $MY_FTP/YAML/roebe_ftp.yml
|
97
|
+
# ======================================================================= #
|
98
|
+
_ = dataset['bytehost']
|
99
|
+
BYTEHOST = [
|
100
|
+
_['url'],
|
101
|
+
_['user_name'],
|
102
|
+
_['password'],
|
103
|
+
_['port']
|
104
|
+
]
|
105
|
+
|
106
|
+
# ======================================================================= #
|
107
|
+
# === UNIVIE
|
108
|
+
#
|
109
|
+
# Uni tag, Univie tag
|
110
|
+
# ======================================================================= #
|
111
|
+
_ = dataset['univie']
|
112
|
+
UNIVIE = [
|
113
|
+
_['url'],
|
114
|
+
_['user_name'],
|
115
|
+
_['password'],
|
116
|
+
_['port']
|
117
|
+
]
|
118
|
+
|
119
|
+
# ======================================================================= #
|
120
|
+
# === Zerofees tag
|
121
|
+
# ======================================================================= #
|
122
|
+
_ = dataset['zerofees']
|
123
|
+
ZEROFEES = [
|
124
|
+
_['url'],
|
125
|
+
_['user_name'],
|
126
|
+
_['password'],
|
127
|
+
_['port']
|
128
|
+
]
|
129
|
+
|
130
|
+
# ======================================================================= #
|
131
|
+
# === UCOZ tag
|
132
|
+
# ======================================================================= #
|
133
|
+
_ = dataset['ucoz']
|
134
|
+
UCOZ = [
|
135
|
+
_['url'],
|
136
|
+
_['user_name'],
|
137
|
+
_['password'],
|
138
|
+
_['port']
|
139
|
+
]
|
140
|
+
|
141
|
+
# ======================================================================= #
|
142
|
+
# === UNIWIEN_HOMEPAGE tag
|
143
|
+
# ======================================================================= #
|
144
|
+
_ = dataset['uniwien_homepage']
|
145
|
+
UNIWIEN_HOMEPAGE = [
|
146
|
+
_['url'],
|
147
|
+
_['user_name'],
|
148
|
+
_['password'],
|
149
|
+
_['port']
|
150
|
+
]
|
151
|
+
|
152
|
+
# ======================================================================= #
|
153
|
+
# === bplaced
|
154
|
+
# ======================================================================= #
|
155
|
+
_ = dataset['bplaced']
|
156
|
+
BPLACED = [
|
157
|
+
_['url'],
|
158
|
+
_['user_name'],
|
159
|
+
_['password'],
|
160
|
+
_['port']
|
161
|
+
]
|
162
|
+
|
163
|
+
# ======================================================================= #
|
164
|
+
# === podserver
|
165
|
+
# ======================================================================= #
|
166
|
+
_ = dataset['podserver']
|
167
|
+
PODSERVER = [
|
168
|
+
_['url'],
|
169
|
+
_['user_name'],
|
170
|
+
_['password'],
|
171
|
+
_['port']
|
172
|
+
]
|
173
|
+
|
174
|
+
# ======================================================================= #
|
175
|
+
# === RoebeFtpConstants::ARRAY_AVAILABLE_HOSTS
|
176
|
+
#
|
177
|
+
# All available hosts are kept in the following Array.
|
178
|
+
#
|
179
|
+
# It is always available when the roebe_ftp.yml file was found.
|
180
|
+
#
|
181
|
+
# Append to this Array if you add new entries above.
|
182
|
+
# ======================================================================= #
|
183
|
+
ARRAY_AVAILABLE_HOSTS = [
|
184
|
+
BYTEHOST.first,
|
185
|
+
A1.first,
|
186
|
+
ZYMIX.first,
|
187
|
+
UNIVIE.first,
|
188
|
+
ZEROFEES.first,
|
189
|
+
UCOZ.first,
|
190
|
+
UNIWIEN_HOMEPAGE.first,
|
191
|
+
PODSERVER.first
|
192
|
+
]
|
193
|
+
end
|
194
|
+
|
195
|
+
# ========================================================================= #
|
196
|
+
# === RoebeFtpConstants.possible_hosts?
|
197
|
+
# ========================================================================= #
|
198
|
+
def self.possible_hosts?
|
199
|
+
ARRAY_AVAILABLE_HOSTS
|
200
|
+
end
|
201
|
+
|
202
|
+
# ========================================================================= #
|
203
|
+
# === RoebeFtpConstants.geas?
|
204
|
+
# ========================================================================= #
|
205
|
+
def self.geas?
|
206
|
+
GEAS
|
207
|
+
end
|
208
|
+
|
209
|
+
# ========================================================================= #
|
210
|
+
# === RoebeFtpConstants.return_user_name_based_on_given_host
|
211
|
+
#
|
212
|
+
# This method may return the proper user name.
|
213
|
+
# ========================================================================= #
|
214
|
+
def self.return_user_name_based_on_given_host(i)
|
215
|
+
if ARRAY_AVAILABLE_HOSTS.include? i
|
216
|
+
i = PODSERVER[1] # Hardcoded for now. [1] is the user-name.
|
217
|
+
end if FtpParadise.const_defined? :RoebeFtpConstants
|
218
|
+
i
|
219
|
+
end
|
220
|
+
|
221
|
+
end; end
|
222
|
+
|
223
|
+
if __FILE__ == $PROGRAM_NAME # Testing RoebeFtpConstants next.
|
224
|
+
require 'cliner'
|
225
|
+
require 'colours/colours_e_autoinclude.rb'
|
226
|
+
include RoebeFtpConstants
|
227
|
+
cliner
|
228
|
+
e RoebeFtpConstants.file?
|
229
|
+
cliner
|
230
|
+
pp RoebeFtpConstants.hash_ftp_dataset?
|
231
|
+
pp RoebeFtpConstants::GEAS
|
232
|
+
pp RoebeFtpConstants.geas?
|
233
|
+
end # $FTP_PARADISE/roebe_ftp_constants.rb
|
@@ -0,0 +1,300 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# === FtpParadise::Entry
|
6
|
+
#
|
7
|
+
# This class is sort of similar to class Net::FTP::List::Entry.
|
8
|
+
#
|
9
|
+
# We want to parse a FTP entry into corresponding slots on the object.
|
10
|
+
#
|
11
|
+
# The input should be an individual line from a remote Net::FTP object.
|
12
|
+
#
|
13
|
+
# The output would be an object such as:
|
14
|
+
#
|
15
|
+
# <FtpParadise::Entry:0x000055561f61b370 @basename="usher-0.0.12.gem", @filesize=2048, @mtime=2014-10-25 00:00:00 +0200, @raw="-rw-r--r-- 1 330 330 6144 Dec 27 2015 usher-0.0.12.gem", @server_type="Unix", @symlink=false, @dir=true, @file=false, @device=false, @splitted=["-rw-r--r--", "1", "330", "330", "6144", "Dec", "27", "2015", "usher-0.0.12.gem"]
|
16
|
+
#
|
17
|
+
# =========================================================================== #
|
18
|
+
# require 'ftp_paradise/entry/entry.rb'
|
19
|
+
# FtpParadise::Entry.new
|
20
|
+
# =========================================================================== #
|
21
|
+
module FtpParadise
|
22
|
+
|
23
|
+
class Entry # === FtpParadise::Entry
|
24
|
+
|
25
|
+
require 'time'
|
26
|
+
|
27
|
+
alias e puts
|
28
|
+
|
29
|
+
attr_reader :basename
|
30
|
+
attr_reader :device
|
31
|
+
attr_reader :raw
|
32
|
+
attr_reader :server_type
|
33
|
+
|
34
|
+
# ========================================================================= #
|
35
|
+
# === FtpParadise::Entry::DEFAULT_INPUT_FOR_THE_ENTRY_CALLED_RAW
|
36
|
+
# ========================================================================= #
|
37
|
+
DEFAULT_INPUT_FOR_THE_ENTRY_CALLED_RAW = 'drwxr-xr-x 2 330 330 2048 Oct 25 2019 .'
|
38
|
+
|
39
|
+
# ========================================================================= #
|
40
|
+
# === initialize
|
41
|
+
# ========================================================================= #
|
42
|
+
def initialize(
|
43
|
+
input_string = ARGV,
|
44
|
+
run_already = true
|
45
|
+
)
|
46
|
+
reset
|
47
|
+
set_raw(input_string)
|
48
|
+
run if run_already
|
49
|
+
end
|
50
|
+
|
51
|
+
# ========================================================================= #
|
52
|
+
# === set_raw
|
53
|
+
# ========================================================================= #
|
54
|
+
def set_raw(i)
|
55
|
+
i = i.first if i.is_a? Array
|
56
|
+
@raw = i.to_s.rstrip
|
57
|
+
if @raw.include? ' '
|
58
|
+
set_splitted(
|
59
|
+
@raw.split(' ')
|
60
|
+
) # Determine @splitted as well here.
|
61
|
+
else
|
62
|
+
# ===================================================================== #
|
63
|
+
# This is for entries that may be short, such as the changed
|
64
|
+
# directory-display for FTP data.
|
65
|
+
# ===================================================================== #
|
66
|
+
@raw = @raw.rjust(67)
|
67
|
+
set_splitted(nil)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# ========================================================================= #
|
72
|
+
# === raw_input?
|
73
|
+
# ========================================================================= #
|
74
|
+
def raw_input?
|
75
|
+
@raw
|
76
|
+
end; alias raw? raw_input? # === raw?
|
77
|
+
|
78
|
+
# ========================================================================= #
|
79
|
+
# === set_splitted
|
80
|
+
# ========================================================================= #
|
81
|
+
def set_splitted(i)
|
82
|
+
@splitted = i
|
83
|
+
end
|
84
|
+
|
85
|
+
# ========================================================================= #
|
86
|
+
# === last
|
87
|
+
#
|
88
|
+
# This should return the name of the file.
|
89
|
+
# ========================================================================= #
|
90
|
+
def last
|
91
|
+
@splitted.last
|
92
|
+
end
|
93
|
+
|
94
|
+
# ========================================================================= #
|
95
|
+
# === symlink?
|
96
|
+
# ========================================================================= #
|
97
|
+
def symlink?
|
98
|
+
@symlink
|
99
|
+
end; alias symlink symlink? # === symlink
|
100
|
+
|
101
|
+
# ========================================================================= #
|
102
|
+
# === reset
|
103
|
+
# ========================================================================= #
|
104
|
+
def reset
|
105
|
+
@basename = '.'
|
106
|
+
@filesize = 0 # Is 0 initially.
|
107
|
+
@mtime = Time.parse('2014-10-25 00:00:00 +0200') # <- This requires time.
|
108
|
+
@raw = DEFAULT_INPUT_FOR_THE_ENTRY_CALLED_RAW
|
109
|
+
@server_type = 'Unix'
|
110
|
+
@symlink = false
|
111
|
+
@directory = true
|
112
|
+
@file = false
|
113
|
+
@device = false
|
114
|
+
end
|
115
|
+
|
116
|
+
# ========================================================================= #
|
117
|
+
# === filesize?
|
118
|
+
# ========================================================================= #
|
119
|
+
def filesize?
|
120
|
+
@filesize
|
121
|
+
end; alias filesize filesize? # === filesize
|
122
|
+
|
123
|
+
# ========================================================================= #
|
124
|
+
# === set_filesize
|
125
|
+
# ========================================================================= #
|
126
|
+
def set_filesize(i)
|
127
|
+
@filesize = i.to_i
|
128
|
+
end
|
129
|
+
|
130
|
+
# ========================================================================= #
|
131
|
+
# === show_the_line
|
132
|
+
# ========================================================================= #
|
133
|
+
def show_the_line
|
134
|
+
e @raw
|
135
|
+
end
|
136
|
+
|
137
|
+
# ========================================================================= #
|
138
|
+
# === is_directory
|
139
|
+
#
|
140
|
+
# Setter method to determine that we have found a directory.
|
141
|
+
# ========================================================================= #
|
142
|
+
def is_directory
|
143
|
+
@symlink = false
|
144
|
+
@file = false
|
145
|
+
@device = false
|
146
|
+
@directory = true
|
147
|
+
end
|
148
|
+
|
149
|
+
# ========================================================================= #
|
150
|
+
# === line?
|
151
|
+
# ========================================================================= #
|
152
|
+
def line?
|
153
|
+
@raw
|
154
|
+
end
|
155
|
+
|
156
|
+
# ========================================================================= #
|
157
|
+
# === name
|
158
|
+
# ========================================================================= #
|
159
|
+
def name
|
160
|
+
@basename
|
161
|
+
end; alias return_name name # === return_name
|
162
|
+
alias name? name # === name?
|
163
|
+
alias filename? name # === filename?
|
164
|
+
|
165
|
+
# ========================================================================= #
|
166
|
+
# === determine_timestamp
|
167
|
+
# ========================================================================= #
|
168
|
+
def determine_timestamp
|
169
|
+
if @splitted
|
170
|
+
new_string = "#{@splitted[5]}-#{@splitted[6]}-#{@splitted[7]}"
|
171
|
+
@mtime = new_string
|
172
|
+
else
|
173
|
+
@mtime = nil
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
# ========================================================================= #
|
178
|
+
# === parsed_timestamp?
|
179
|
+
# ========================================================================= #
|
180
|
+
def parsed_timestamp?
|
181
|
+
Time.parse(@mtime)
|
182
|
+
end
|
183
|
+
|
184
|
+
# ========================================================================= #
|
185
|
+
# === determine_filesize
|
186
|
+
#
|
187
|
+
# This method will determine the filesize of our remote entry at
|
188
|
+
# hand. The input may look like this:
|
189
|
+
# "-rw-rw-rw- 1 web netscape 10548 May 30 2011 Chained.rb"
|
190
|
+
# So when we split on ' ', the filesize will be entry number 4.
|
191
|
+
# ========================================================================= #
|
192
|
+
def determine_filesize
|
193
|
+
if @splitted
|
194
|
+
set_filesize(@splitted[4])
|
195
|
+
else
|
196
|
+
set_filesize(0)
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
# ========================================================================= #
|
201
|
+
# === determine_basename
|
202
|
+
# ========================================================================= #
|
203
|
+
def determine_basename
|
204
|
+
if @splitted
|
205
|
+
@basename = @splitted.last
|
206
|
+
else
|
207
|
+
@basename = raw
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
# ========================================================================= #
|
212
|
+
# === is_a_directory?
|
213
|
+
# ========================================================================= #
|
214
|
+
def is_a_directory?
|
215
|
+
@basename.end_with?('/') or @raw.start_with?('d')
|
216
|
+
end; alias is_directory? is_a_directory? # === is_directory?
|
217
|
+
|
218
|
+
# ========================================================================= #
|
219
|
+
# === file_or_directory?
|
220
|
+
#
|
221
|
+
# This will return the string 'file' or the string 'directory',
|
222
|
+
# depending on whether we have a file or a directory.
|
223
|
+
# ========================================================================= #
|
224
|
+
def file_or_directory?
|
225
|
+
if is_directory?
|
226
|
+
'directory'
|
227
|
+
else
|
228
|
+
'file'
|
229
|
+
end
|
230
|
+
end; alias file_or_directory file_or_directory? # === file_or_directory
|
231
|
+
alias type? file_or_directory? # === type?
|
232
|
+
|
233
|
+
# ========================================================================= #
|
234
|
+
# === directory?
|
235
|
+
# ========================================================================= #
|
236
|
+
def directory?
|
237
|
+
@directory
|
238
|
+
end; alias dir directory? # === dir
|
239
|
+
alias dir? directory? # === dir?
|
240
|
+
|
241
|
+
# ========================================================================= #
|
242
|
+
# === is_a_file?
|
243
|
+
# ========================================================================= #
|
244
|
+
def is_a_file?
|
245
|
+
!is_a_directory?
|
246
|
+
end
|
247
|
+
|
248
|
+
# ========================================================================= #
|
249
|
+
# === mtime?
|
250
|
+
# ========================================================================= #
|
251
|
+
def mtime?
|
252
|
+
@mtime
|
253
|
+
end; alias mtime mtime? # === mtime
|
254
|
+
|
255
|
+
# ========================================================================= #
|
256
|
+
# === file?
|
257
|
+
# ========================================================================= #
|
258
|
+
def file?
|
259
|
+
@file
|
260
|
+
end; alias file file? # === file
|
261
|
+
|
262
|
+
# ========================================================================= #
|
263
|
+
# === run
|
264
|
+
# ========================================================================= #
|
265
|
+
def run
|
266
|
+
case @raw[0,1]
|
267
|
+
when 'd' # If it starts with a 'd', then it is a directory.
|
268
|
+
is_directory
|
269
|
+
end
|
270
|
+
determine_basename
|
271
|
+
determine_timestamp
|
272
|
+
determine_filesize
|
273
|
+
end
|
274
|
+
|
275
|
+
# ========================================================================= #
|
276
|
+
# === Entry.parse
|
277
|
+
# ========================================================================= #
|
278
|
+
def self.parse(i)
|
279
|
+
new(i)
|
280
|
+
end
|
281
|
+
|
282
|
+
end; end
|
283
|
+
|
284
|
+
if __FILE__ == $PROGRAM_NAME
|
285
|
+
alias e puts
|
286
|
+
array = ["-rw-r--r-- 1 0 2 0 Oct 29 19:23 DO NOT UPLOAD FILES HERE",
|
287
|
+
"htdocs/",
|
288
|
+
"-rw-r--r-- 1 22918231 22918231 9 Oct 29 19:32 test.md",
|
289
|
+
"drwxr-xr-x 2 22918231 22918231 4096 Oct 30 10:59 test2"]
|
290
|
+
array.map! {|line|
|
291
|
+
FtpParadise::Entry.new(line)
|
292
|
+
}
|
293
|
+
pp array
|
294
|
+
entry = array[1]
|
295
|
+
e
|
296
|
+
pp entry
|
297
|
+
e
|
298
|
+
puts entry.file_or_directory?
|
299
|
+
puts entry.type?
|
300
|
+
end
|