ftp_paradise 1.4.5 → 1.5.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +155 -28
- data/bin/{iftp → ftp_paradise_shell} +1 -1
- data/doc/README.gen +97 -15
- data/doc/todo/{TODO_FOR_FTP_PARADISE_PROJECT.md → todo_for_the_ftp_paradise_project.md} +11 -1
- data/ftp_paradise.gemspec +30 -39
- data/lib/ftp_paradise/base/base.rb +375 -0
- data/lib/ftp_paradise/colours/colours.rb +27 -27
- data/lib/ftp_paradise/colours/use_colours.rb +6 -1
- data/lib/ftp_paradise/configuration/configuration.rb +7 -4
- data/lib/ftp_paradise/connection/README.md +0 -0
- data/lib/ftp_paradise/connection/connection.rb +2782 -15
- data/lib/ftp_paradise/constants/constants.rb +91 -5
- data/lib/ftp_paradise/entry/entry.rb +42 -5
- data/lib/ftp_paradise/{connection → gui/gtk3/ftp_client}/constants.rb +33 -21
- data/lib/ftp_paradise/gui/{shared_code/ftp_paradise/ftp_paradise_module.rb → gtk3/ftp_client/ftp_client.rb} +658 -170
- data/lib/ftp_paradise/gui/gtk3/ftp_client/misc.rb +27 -0
- data/lib/ftp_paradise/project/project.rb +11 -15
- data/lib/ftp_paradise/requires/require_class_connection.rb +7 -0
- data/lib/ftp_paradise/requires/require_net_ftp.rb +7 -0
- data/lib/ftp_paradise/requires/require_the_ftp_paradise_project.rb +4 -3
- data/lib/ftp_paradise/requires/require_the_ftp_paradise_project_with_the_GUI_bindings.rb +1 -1
- data/lib/ftp_paradise/requires/require_the_toplevel_methods.rb +1 -0
- data/lib/ftp_paradise/{interactive_ftp → shell}/menu.rb +564 -449
- data/lib/ftp_paradise/shell/shell.rb +2321 -0
- data/lib/ftp_paradise/toplevel_methods/connect.rb +3 -0
- data/lib/ftp_paradise/toplevel_methods/dataset.rb +111 -0
- data/lib/ftp_paradise/toplevel_methods/file_related_actions.rb +4 -3
- data/lib/ftp_paradise/toplevel_methods/ftp_object.rb +6 -5
- data/lib/ftp_paradise/toplevel_methods/login_name.rb +6 -4
- data/lib/ftp_paradise/toplevel_methods/misc.rb +19 -0
- data/lib/ftp_paradise/toplevel_methods/opn.rb +1 -1
- data/lib/ftp_paradise/toplevel_methods/password.rb +4 -2
- data/lib/ftp_paradise/toplevel_methods/port.rb +4 -1
- data/lib/ftp_paradise/toplevel_methods/remote_url.rb +11 -5
- data/lib/ftp_paradise/toplevel_methods/upload_and_download.rb +1 -0
- data/lib/ftp_paradise/version/version.rb +6 -1
- data/lib/ftp_paradise/www/web_interface.cgi +1 -1
- data/lib/ftp_paradise/yaml/automatically_connect_on_startup_of_the_interactive_ftp_shell.yml +0 -0
- data/lib/ftp_paradise/yaml/debug.yml +0 -0
- data/lib/ftp_paradise/yaml/open_in_default_editor.yml +0 -0
- data/lib/ftp_paradise/yaml/show_full_names.yml +0 -0
- data/lib/ftp_paradise/yaml/use_colours.yml +0 -0
- data/test/testing_minimal_pure_net_ftp_example_to_connect.rb +13 -3
- metadata +52 -126
- data/lib/ftp_paradise/base/cliner.rb +0 -23
- data/lib/ftp_paradise/base/colours.rb +0 -83
- data/lib/ftp_paradise/base/prototype.rb +0 -171
- data/lib/ftp_paradise/base/reset.rb +0 -29
- data/lib/ftp_paradise/connection/data.rb +0 -164
- data/lib/ftp_paradise/connection/debug.rb +0 -78
- data/lib/ftp_paradise/connection/directory_handling.rb +0 -271
- data/lib/ftp_paradise/connection/do_login.rb +0 -108
- data/lib/ftp_paradise/connection/download.rb +0 -86
- data/lib/ftp_paradise/connection/file_handling.rb +0 -174
- data/lib/ftp_paradise/connection/ftp_object.rb +0 -21
- data/lib/ftp_paradise/connection/initialize.rb +0 -88
- data/lib/ftp_paradise/connection/initialize_a_new_net_ftp_object_with_this_url.rb +0 -20
- data/lib/ftp_paradise/connection/is_connected.rb +0 -46
- data/lib/ftp_paradise/connection/misc.rb +0 -474
- data/lib/ftp_paradise/connection/notify.rb +0 -71
- data/lib/ftp_paradise/connection/password.rb +0 -47
- data/lib/ftp_paradise/connection/port.rb +0 -33
- data/lib/ftp_paradise/connection/remote_pwd.rb +0 -72
- data/lib/ftp_paradise/connection/remote_url.rb +0 -164
- data/lib/ftp_paradise/connection/remove.rb +0 -143
- data/lib/ftp_paradise/connection/reset.rb +0 -78
- data/lib/ftp_paradise/connection/run.rb +0 -18
- data/lib/ftp_paradise/connection/set_array_available_hosts.rb +0 -27
- data/lib/ftp_paradise/connection/set_input.rb +0 -18
- data/lib/ftp_paradise/connection/show.rb +0 -153
- data/lib/ftp_paradise/connection/sync_ftp_object_onto_the_main_namespace.rb +0 -24
- data/lib/ftp_paradise/connection/transfer_mode.rb +0 -163
- data/lib/ftp_paradise/connection/upload.rb +0 -253
- data/lib/ftp_paradise/connection/use_default_dataset.rb +0 -40
- data/lib/ftp_paradise/connection/username.rb +0 -42
- data/lib/ftp_paradise/constants/misc.rb +0 -57
- data/lib/ftp_paradise/constants/namespace.rb +0 -14
- data/lib/ftp_paradise/constants/newline.rb +0 -14
- data/lib/ftp_paradise/constants/roebe.rb +0 -31
- data/lib/ftp_paradise/constants/roebe_ftp_constants.rb +0 -233
- data/lib/ftp_paradise/gui/gtk2/ftp_paradise.rb +0 -34
- data/lib/ftp_paradise/gui/gtk3/ftp_paradise.rb +0 -34
- data/lib/ftp_paradise/interactive_ftp/constants.rb +0 -103
- data/lib/ftp_paradise/interactive_ftp/directory_handling.rb +0 -216
- data/lib/ftp_paradise/interactive_ftp/help.rb +0 -50
- data/lib/ftp_paradise/interactive_ftp/initialize.rb +0 -27
- data/lib/ftp_paradise/interactive_ftp/interactive_ftp.rb +0 -998
- data/lib/ftp_paradise/interactive_ftp/main_loop.rb +0 -51
- data/lib/ftp_paradise/interactive_ftp/misc.rb +0 -208
- data/lib/ftp_paradise/interactive_ftp/mode.rb +0 -124
- data/lib/ftp_paradise/interactive_ftp/readline.rb +0 -113
- data/lib/ftp_paradise/interactive_ftp/remove.rb +0 -97
- data/lib/ftp_paradise/interactive_ftp/reset.rb +0 -90
- data/lib/ftp_paradise/interactive_ftp/run.rb +0 -22
- data/lib/ftp_paradise/interactive_ftp/show.rb +0 -184
- data/lib/ftp_paradise/interactive_ftp/upload.rb +0 -90
- data/lib/ftp_paradise/interactive_ftp/user_input.rb +0 -53
- data/lib/ftp_paradise/toplevel_methods/can_connect_to_remote_site.rb +0 -28
- data/lib/ftp_paradise/toplevel_methods/clear_user_dataset.rb +0 -28
- data/lib/ftp_paradise/toplevel_methods/data.rb +0 -31
- data/lib/ftp_paradise/toplevel_methods/determine_user_dataset_from_this_hash.rb +0 -37
@@ -1,164 +0,0 @@
|
|
1
|
-
#!/usr/bin/ruby -w
|
2
|
-
# Encoding: UTF-8
|
3
|
-
# frozen_string_literal: true
|
4
|
-
# =========================================================================== #
|
5
|
-
# require 'ftp_paradise/connection/data.rb'
|
6
|
-
# =========================================================================== #
|
7
|
-
module FtpParadise
|
8
|
-
|
9
|
-
class Connection
|
10
|
-
|
11
|
-
require 'ftp_paradise/constants/roebe.rb'
|
12
|
-
|
13
|
-
# ========================================================================= #
|
14
|
-
# === set_data (all in one, set_data tag)
|
15
|
-
#
|
16
|
-
# This method sets:
|
17
|
-
#
|
18
|
-
# - host
|
19
|
-
# - user name
|
20
|
-
# - port and
|
21
|
-
# - password
|
22
|
-
#
|
23
|
-
# This method is thus a nifty little convenience method. You can pass
|
24
|
-
# a hash to it too, which is the recommended way to use this method.
|
25
|
-
#
|
26
|
-
# You can also use an Array (with 4 elements), in which case we will
|
27
|
-
# process it one after the other. The reason for this procedure is
|
28
|
-
# because we can also use yaml files that way, that also use the
|
29
|
-
# exact order of elements.
|
30
|
-
#
|
31
|
-
# If you add a new entry to the case menu below, also add this to
|
32
|
-
# ARRAY_AVAILABLE_HOSTS, please. That Array can be found in the
|
33
|
-
# file 'constants/roebe_ftp_constants.rb'.
|
34
|
-
# ========================================================================= #
|
35
|
-
def set_data(
|
36
|
-
i = 'default'
|
37
|
-
) # set the default here.
|
38
|
-
if debug?
|
39
|
-
opnn; e 'We will debug next, as the @debug variable was set to true.'
|
40
|
-
pp i
|
41
|
-
end
|
42
|
-
# ======================================================================= #
|
43
|
-
# === Handle Hash as input first
|
44
|
-
# ======================================================================= #
|
45
|
-
if i.is_a? Hash # Hash is treated differently.
|
46
|
-
|
47
|
-
# ===================================================================== #
|
48
|
-
# === :host
|
49
|
-
# ===================================================================== #
|
50
|
-
if i.has_key? :host
|
51
|
-
set_host i.fetch(:host)
|
52
|
-
elsif i.has_key? :remote_host
|
53
|
-
set_host i.fetch(:remote_host)
|
54
|
-
elsif i.has_key? :to # :to is an alias to :host.
|
55
|
-
set_host i.fetch(:to)
|
56
|
-
end
|
57
|
-
|
58
|
-
# ===================================================================== #
|
59
|
-
# === :user_name
|
60
|
-
# ===================================================================== #
|
61
|
-
if i.has_key? :user_name
|
62
|
-
set_user_name i.fetch(:user_name)
|
63
|
-
elsif i.has_key? :login_name
|
64
|
-
set_user_name i.fetch(:login_name)
|
65
|
-
end
|
66
|
-
|
67
|
-
# ===================================================================== #
|
68
|
-
# === :password
|
69
|
-
# ===================================================================== #
|
70
|
-
if i.has_key? :password
|
71
|
-
set_password i.fetch(:password)
|
72
|
-
elsif i.has_key? :login_password
|
73
|
-
set_password i.fetch(:login_password)
|
74
|
-
end
|
75
|
-
|
76
|
-
# ===================================================================== #
|
77
|
-
# === :port
|
78
|
-
# ===================================================================== #
|
79
|
-
if i.has_key? :port
|
80
|
-
set_port i.fetch(:port)
|
81
|
-
end
|
82
|
-
# ======================================================================= #
|
83
|
-
# === Handle Array as input next
|
84
|
-
# ======================================================================= #
|
85
|
-
elsif i.is_a? Array # Example-Array: ["ftp.byethost33.com", "b33_14144659", "1aaaaaa", 21]
|
86
|
-
set_host i.first
|
87
|
-
set_user_name i[1]
|
88
|
-
set_password i[2]
|
89
|
-
set_port i[3]
|
90
|
-
# ======================================================================= #
|
91
|
-
# === Else, use simple toggle commands, such as 1,2,3,4,5 and so forth.
|
92
|
-
# ======================================================================= #
|
93
|
-
else # In the following case menu you can toggle your FTP.
|
94
|
-
case i.to_s # Work on strings only. Assumes shortcuts.
|
95
|
-
# ===================================================================== #
|
96
|
-
# === shevy
|
97
|
-
#
|
98
|
-
# This defaults to my home system.
|
99
|
-
# ===================================================================== #
|
100
|
-
when '6',
|
101
|
-
/shevy/i,
|
102
|
-
'square',
|
103
|
-
'square7',
|
104
|
-
'bplaced',
|
105
|
-
'podserver',
|
106
|
-
'default',
|
107
|
-
'top' # Current default.
|
108
|
-
_ = FILE_ROEBE_FTP
|
109
|
-
if File.exist? _
|
110
|
-
data = YAML.load_file(_)['podserver'] # 'bplaced'
|
111
|
-
set_host data['url']
|
112
|
-
set_user_name data['user_name']
|
113
|
-
this_password = data['password']
|
114
|
-
this_password.chop! if this_password.end_with? '_'
|
115
|
-
set_password this_password
|
116
|
-
set_port data['port']
|
117
|
-
end
|
118
|
-
# ===================================================================== #
|
119
|
-
# === a1
|
120
|
-
# ===================================================================== #
|
121
|
-
when '1',
|
122
|
-
'a1',
|
123
|
-
'a1_ftp' # A1 FTP host. No longer in use but still kept.
|
124
|
-
set_host A1.first
|
125
|
-
set_user_name A1[1]
|
126
|
-
set_password A1[2]
|
127
|
-
set_port A1[3]
|
128
|
-
# ===================================================================== #
|
129
|
-
# === zymix
|
130
|
-
# ===================================================================== #
|
131
|
-
when '2',
|
132
|
-
'zymix',
|
133
|
-
'standard'
|
134
|
-
set_host ZYMIX.first
|
135
|
-
set_user_name ZYMIX[1]
|
136
|
-
set_password ZYMIX[2]
|
137
|
-
set_port ZYMIX[3]
|
138
|
-
# ===================================================================== #
|
139
|
-
# === uniwien
|
140
|
-
# ===================================================================== #
|
141
|
-
when '3',
|
142
|
-
'univie',
|
143
|
-
'uniwien' # Uni Wien FTP Account.
|
144
|
-
set_host UNIVIE.first
|
145
|
-
set_user_name UNIVIE[1]
|
146
|
-
set_password UNIVIE[2]
|
147
|
-
set_port UNIVIE[3]
|
148
|
-
# ===================================================================== #
|
149
|
-
# === byte
|
150
|
-
# ===================================================================== #
|
151
|
-
when '4',
|
152
|
-
'byte',
|
153
|
-
'bytehost'
|
154
|
-
set_host BYTEHOST.first
|
155
|
-
set_user_name BYTEHOST[1]
|
156
|
-
set_password BYTEHOST[2]
|
157
|
-
set_port BYTEHOST[3]
|
158
|
-
else
|
159
|
-
set_data(:default) # Go back to default again if not found.
|
160
|
-
end
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
end; end
|
@@ -1,78 +0,0 @@
|
|
1
|
-
#!/usr/bin/ruby -w
|
2
|
-
# Encoding: UTF-8
|
3
|
-
# frozen_string_literal: true
|
4
|
-
# =========================================================================== #
|
5
|
-
# require 'ftp_paradise/connection/debug.rb'
|
6
|
-
# =========================================================================== #
|
7
|
-
module FtpParadise
|
8
|
-
|
9
|
-
class Connection
|
10
|
-
|
11
|
-
# ========================================================================= #
|
12
|
-
# === set_debug
|
13
|
-
# ========================================================================= #
|
14
|
-
def set_debug(i = SHALL_WE_DEBUG)
|
15
|
-
@internal_hash[:debug] = i
|
16
|
-
end
|
17
|
-
|
18
|
-
# ========================================================================= #
|
19
|
-
# === enable_debug_mode
|
20
|
-
#
|
21
|
-
# When the debug mode is set to true, then all traffic to and from
|
22
|
-
# the server is written to $stdout. By default, this will NOT
|
23
|
-
# be the case.
|
24
|
-
# ========================================================================= #
|
25
|
-
def enable_debug_mode
|
26
|
-
ftp_object?.debug_mode = true
|
27
|
-
end
|
28
|
-
|
29
|
-
# ========================================================================= #
|
30
|
-
# === enable_debug
|
31
|
-
#
|
32
|
-
# Set the @debug variable to true, and also invoke enable_debug_mode().
|
33
|
-
# ========================================================================= #
|
34
|
-
def enable_debug
|
35
|
-
enable_debug_mode
|
36
|
-
set_debug(true)
|
37
|
-
end
|
38
|
-
|
39
|
-
# ========================================================================= #
|
40
|
-
# === debug?
|
41
|
-
# ========================================================================= #
|
42
|
-
def debug?
|
43
|
-
@internal_hash[:debug]
|
44
|
-
end
|
45
|
-
|
46
|
-
# ========================================================================= #
|
47
|
-
# === disable_debug
|
48
|
-
# ========================================================================= #
|
49
|
-
def disable_debug
|
50
|
-
ftp_object?.debug_mode = false
|
51
|
-
@internal_hash[:debug] = false
|
52
|
-
end
|
53
|
-
|
54
|
-
# ========================================================================= #
|
55
|
-
# === debug (debug tag)
|
56
|
-
#
|
57
|
-
# This method can be used for some debugging output.
|
58
|
-
# ========================================================================= #
|
59
|
-
def debug(
|
60
|
-
shall_we_debug = debug?
|
61
|
-
)
|
62
|
-
cliner {
|
63
|
-
pp ftp?
|
64
|
-
show_host_user_name_port_and_password
|
65
|
-
update_file_listing
|
66
|
-
if shall_we_debug
|
67
|
-
opnn; e 'File Listing:'
|
68
|
-
show_file_listing
|
69
|
-
end
|
70
|
-
if remote_file_listing?.empty?
|
71
|
-
opnn; e 'No file could be found. The remote directory '\
|
72
|
-
'is most likely empty.'
|
73
|
-
end
|
74
|
-
} if shall_we_debug
|
75
|
-
end; alias feedback debug # === feedback
|
76
|
-
alias report debug # === report
|
77
|
-
|
78
|
-
end; end
|
@@ -1,271 +0,0 @@
|
|
1
|
-
#!/usr/bin/ruby -w
|
2
|
-
# Encoding: UTF-8
|
3
|
-
# frozen_string_literal: true
|
4
|
-
# =========================================================================== #
|
5
|
-
# require 'ftp_paradise/connection/directory_handling.rb'
|
6
|
-
# =========================================================================== #
|
7
|
-
module FtpParadise
|
8
|
-
|
9
|
-
class Connection
|
10
|
-
|
11
|
-
require 'ftp_paradise/connection/remote_pwd.rb'
|
12
|
-
require 'ftp_paradise/connection/file_handling.rb'
|
13
|
-
|
14
|
-
# ========================================================================= #
|
15
|
-
# === report_current_remote_dir
|
16
|
-
#
|
17
|
-
# Gives you the current dir.
|
18
|
-
# ========================================================================= #
|
19
|
-
def report_current_remote_dir(
|
20
|
-
be_verbose = be_verbose?
|
21
|
-
)
|
22
|
-
begin
|
23
|
-
if be_verbose
|
24
|
-
opnn; e 'The remote directory is:'
|
25
|
-
e " #{sdir(return_remote_pwd)}"
|
26
|
-
end
|
27
|
-
rescue Exception => error
|
28
|
-
opnn; e error.class
|
29
|
-
opnn; e error
|
30
|
-
end
|
31
|
-
end; alias report_remote_directory report_current_remote_dir # === report_remote_directory
|
32
|
-
alias dir? report_current_remote_dir # === dir?
|
33
|
-
alias report_remote_pwd report_current_remote_dir # === report_remote_pwd
|
34
|
-
|
35
|
-
# ========================================================================= #
|
36
|
-
# === remote_chdir (cd tag, chdir tag)
|
37
|
-
#
|
38
|
-
# This method allows us to cd to another remote directory, on the
|
39
|
-
# remote FTP server (our main connection).
|
40
|
-
#
|
41
|
-
# The method must be able to check whether we are connected to the
|
42
|
-
# remote host.
|
43
|
-
# ========================================================================= #
|
44
|
-
def remote_chdir(
|
45
|
-
i,
|
46
|
-
be_verbose = be_verbose?
|
47
|
-
)
|
48
|
-
i = i.dup if i.frozen?
|
49
|
-
# ======================================================================= #
|
50
|
-
# Sanitize odd entries ending with ':'
|
51
|
-
# ======================================================================= #
|
52
|
-
i[-1,1] = '/' if i.end_with? ':'
|
53
|
-
i = rds("#{i}/") # <- Always ensure that a '/' is the last character.
|
54
|
-
if be_verbose
|
55
|
-
notify_the_user_about(i, __method__)
|
56
|
-
end
|
57
|
-
if is_connected?
|
58
|
-
# ===================================================================== #
|
59
|
-
# If we cd to a non-existing target, the exception Net::FTPPermError
|
60
|
-
# will be raised.
|
61
|
-
# ===================================================================== #
|
62
|
-
begin
|
63
|
-
ftp_object?.chdir(i)
|
64
|
-
update_remote_file_listing
|
65
|
-
# ===================================================================== #
|
66
|
-
# The user may have insufficient permissions:
|
67
|
-
# ===================================================================== #
|
68
|
-
rescue Net::FTPPermError => error
|
69
|
-
pp error
|
70
|
-
rescue Net::ReadTimeout => error
|
71
|
-
opnn; e 'An error was encountered in the method '\
|
72
|
-
'remote_chdir().'
|
73
|
-
opnn; e 'The error-class was Net::ReadTimeout.'
|
74
|
-
e
|
75
|
-
opnn; e 'The specific error will be displayed next.'
|
76
|
-
e
|
77
|
-
pp error
|
78
|
-
end
|
79
|
-
else
|
80
|
-
opnn; e 'We are not connected to a remote host right now.'
|
81
|
-
opnn; e 'Thus we can not change the directory.'
|
82
|
-
end
|
83
|
-
report_current_remote_dir if be_verbose # right now mandatory
|
84
|
-
end; alias rcd remote_chdir # === rcd
|
85
|
-
alias remote_cd remote_chdir # === remote_cd
|
86
|
-
alias chdir remote_chdir # === chdir
|
87
|
-
alias cd remote_chdir # === cd
|
88
|
-
alias chdir remote_chdir # === chdir
|
89
|
-
alias rcd remote_chdir # === rcd
|
90
|
-
alias change_directory remote_chdir # === change_directory
|
91
|
-
alias change_remote_directory remote_chdir # === change_remote_directory
|
92
|
-
alias cd_into_this_remote_directory remote_chdir # === cd_into_this_remote_directory
|
93
|
-
alias remote_change_directory remote_chdir # === remote_change_directory
|
94
|
-
|
95
|
-
# ========================================================================= #
|
96
|
-
# === return_remote_directories
|
97
|
-
#
|
98
|
-
# Give us a list of (remote) directories - only directories, not
|
99
|
-
# files.
|
100
|
-
#
|
101
|
-
# An Array will be returned as a result.
|
102
|
-
# ========================================================================= #
|
103
|
-
def return_remote_directories
|
104
|
-
_ = []
|
105
|
-
update_file_listing # Populate the file listing anew, so we will always get proper results back.
|
106
|
-
raw_listing?.each {|entry|
|
107
|
-
entry = FtpParadise::Entry.new(entry)
|
108
|
-
_ << rds(entry.return_name) if entry.is_a_directory?
|
109
|
-
}
|
110
|
-
# ======================================================================= #
|
111
|
-
# Directories must end with '/'. Ensure this to be the case next.
|
112
|
-
# ======================================================================= #
|
113
|
-
_.map! {|entry|
|
114
|
-
entry << '/' unless entry.end_with? '/'
|
115
|
-
entry
|
116
|
-
}
|
117
|
-
return _
|
118
|
-
end; alias directories? return_remote_directories # === directories?
|
119
|
-
alias return_directories return_remote_directories # === return_directories
|
120
|
-
|
121
|
-
# ========================================================================= #
|
122
|
-
# === return_remote_directory_content
|
123
|
-
#
|
124
|
-
# This method will return ALL remote entries, no matter if file or
|
125
|
-
# directory.
|
126
|
-
# ========================================================================= #
|
127
|
-
def return_remote_directory_content
|
128
|
-
raw_entries = raw_entries?
|
129
|
-
if raw_entries.nil?
|
130
|
-
populate_raw_entries
|
131
|
-
raw_entries = raw_entries?
|
132
|
-
end
|
133
|
-
if raw_entries
|
134
|
-
_ = raw_entries.reject {|line|
|
135
|
-
line.empty?
|
136
|
-
}.map {|entry|
|
137
|
-
FtpParadise::Entry.new(entry).name?
|
138
|
-
}
|
139
|
-
end
|
140
|
-
return _
|
141
|
-
end; alias array_file_listing? return_remote_directory_content # === array_file_listing?
|
142
|
-
alias array_file_listing return_remote_directory_content # === array_file_listing
|
143
|
-
alias remote_directory_content return_remote_directory_content # === remote_directory_content
|
144
|
-
alias list? return_remote_directory_content # === list?
|
145
|
-
|
146
|
-
# ========================================================================= #
|
147
|
-
# === is_a_directory?
|
148
|
-
#
|
149
|
-
# This method queries whether the given input is a (remote) directory.
|
150
|
-
# For this to work, the given input must obviously exist as file or
|
151
|
-
# directory.
|
152
|
-
# ========================================================================= #
|
153
|
-
def is_a_directory?(i)
|
154
|
-
update_file_listing
|
155
|
-
candidates = file_listing_as_entries?.select {|entry|
|
156
|
-
entry.is_a_directory?
|
157
|
-
}.map(&:last)
|
158
|
-
candidates.include? i
|
159
|
-
end; alias is_directory? is_a_directory? # === is_directory?
|
160
|
-
alias is_a_directory? is_a_directory? # === is_a_directory?
|
161
|
-
alias this_remote_directory_exists? is_a_directory? # === this_remote_directory_exists?
|
162
|
-
alias is_dir? is_a_directory? # === is_dir?
|
163
|
-
|
164
|
-
# ========================================================================= #
|
165
|
-
# === remote_directory_is_empty?
|
166
|
-
#
|
167
|
-
# This method will return a Boolean - true if the remote directory
|
168
|
-
# is empty, and false otherwise.
|
169
|
-
# ========================================================================= #
|
170
|
-
def remote_directory_is_empty?
|
171
|
-
_ = return_remote_directory_content
|
172
|
-
_.reject! {|entry|
|
173
|
-
(entry == '.') or (entry == '..')
|
174
|
-
}
|
175
|
-
_.empty?
|
176
|
-
end
|
177
|
-
|
178
|
-
# ========================================================================= #
|
179
|
-
# === create_this_remote_directory (mkdir tag)
|
180
|
-
#
|
181
|
-
# This method will attempt to create a remote directory.
|
182
|
-
#
|
183
|
-
# A Net::FTPPermError may result if the permission does not allow for
|
184
|
-
# that action.
|
185
|
-
# ========================================================================= #
|
186
|
-
def create_this_remote_directory(
|
187
|
-
i, be_verbose = be_verbose?
|
188
|
-
)
|
189
|
-
if i.is_a? Array
|
190
|
-
i.each {|entry| create_this_remote_directory(entry, be_verbose) }
|
191
|
-
else
|
192
|
-
i = rds(i+'/')
|
193
|
-
if be_verbose
|
194
|
-
notify_the_user_about(i, __method__)
|
195
|
-
if is_directory?(i)
|
196
|
-
opnn; e swarn('Warning - the remote directory ')+
|
197
|
-
sdir(i)+swarn(' already exists.')
|
198
|
-
opnn; e swarn('We thus can not create a new directory.')
|
199
|
-
end
|
200
|
-
end
|
201
|
-
begin
|
202
|
-
ftp_object?.mkdir(i)
|
203
|
-
rescue Net::FTPConnectionError
|
204
|
-
opnn; e 'Not connected - is the network down/available?'
|
205
|
-
rescue Net::FTPPermError
|
206
|
-
opnn; e "Net::FTPPermError: Can not create the remote "\
|
207
|
-
"directory `#{remote_path?}#{sdir(i)}`"
|
208
|
-
opnn; e 'as it - or a file with the same name - already exists.'
|
209
|
-
end
|
210
|
-
end
|
211
|
-
end; alias mkdir create_this_remote_directory # === mkdir
|
212
|
-
alias rmkdir create_this_remote_directory # === rmkdir
|
213
|
-
alias remote_mkdir create_this_remote_directory # === remote_mkdir
|
214
|
-
alias create_directory create_this_remote_directory # === create_directory
|
215
|
-
alias create_these_remote_directories create_this_remote_directory # === create_these_remote_directories
|
216
|
-
alias remote_create_directory create_this_remote_directory # === remote_create_directory
|
217
|
-
alias create_remote_directory create_this_remote_directory # === create_remote_directory
|
218
|
-
|
219
|
-
# ========================================================================= #
|
220
|
-
# === sanitize_remote_directory_content
|
221
|
-
#
|
222
|
-
# The purpose of this method is to clean up the remote dataset.
|
223
|
-
#
|
224
|
-
# Keep in mind that the output comes in something like:
|
225
|
-
#
|
226
|
-
# "-rw-rw-rw- 1 web netscape 6820 May 30 2011 AppendToCookbook.rb"
|
227
|
-
# "drwxrwxrwx 2 web netscape 8192 Oct 29 2007 CSS"
|
228
|
-
# "-rw-rw-rw- 1 web netscape 10548 May 30 2011 Chained.rb"
|
229
|
-
# "-rw-r--r-- 1 330 330 237904 Jun 9 14:24 11.03.2003_UniWien_Biologie_EinfuehrungInDieMikrobiologie.jpg",
|
230
|
-
#
|
231
|
-
# This should contain all the information that is needed.
|
232
|
-
# ========================================================================= #
|
233
|
-
def sanitize_remote_directory_content
|
234
|
-
_ = []
|
235
|
-
raw_entries?.each { |e|
|
236
|
-
next if e.empty?
|
237
|
-
entry = FtpParadise::Entry.new(e)
|
238
|
-
filesize = entry.filesize?
|
239
|
-
timestamp = entry.parsed_timestamp?
|
240
|
-
# ===================================================================== #
|
241
|
-
# === Exclude 3 entries next
|
242
|
-
# ===================================================================== #
|
243
|
-
next if e.include? 'total' or
|
244
|
-
entry.name? == '.' or
|
245
|
-
entry.name? == '..' # Batch next.
|
246
|
-
# ===================================================================== #
|
247
|
-
# === Build up the final Array
|
248
|
-
#
|
249
|
-
# Our Array will have four entries:
|
250
|
-
#
|
251
|
-
# (1) Filename
|
252
|
-
# (2) File or Directory (String)
|
253
|
-
# (3) Filesize
|
254
|
-
# (4) Timestamp
|
255
|
-
#
|
256
|
-
# ===================================================================== #
|
257
|
-
_ << [ rds(entry.filename?), entry.file_or_directory, filesize, timestamp ]
|
258
|
-
}
|
259
|
-
@internal_hash[:sanitized_remote_directory_content] = _ #.compact
|
260
|
-
end
|
261
|
-
|
262
|
-
# ========================================================================= #
|
263
|
-
# === sanitized_remote_directory_content?
|
264
|
-
# ========================================================================= #
|
265
|
-
def sanitized_remote_directory_content?
|
266
|
-
update_remote_file_listing
|
267
|
-
sanitize_remote_directory_content
|
268
|
-
@internal_hash[:sanitized_remote_directory_content]
|
269
|
-
end
|
270
|
-
|
271
|
-
end; end
|
@@ -1,108 +0,0 @@
|
|
1
|
-
#!/usr/bin/ruby -w
|
2
|
-
# Encoding: UTF-8
|
3
|
-
# frozen_string_literal: true
|
4
|
-
# =========================================================================== #
|
5
|
-
# require 'ftp_paradise/connection/do_login.rb'
|
6
|
-
# =========================================================================== #
|
7
|
-
module FtpParadise
|
8
|
-
|
9
|
-
class Connection
|
10
|
-
|
11
|
-
require 'ftp_paradise/toplevel_methods/remote_url.rb'
|
12
|
-
|
13
|
-
require 'ftp_paradise/connection/initialize_a_new_net_ftp_object_with_this_url.rb'
|
14
|
-
require 'ftp_paradise/connection/is_connected.rb'
|
15
|
-
require 'ftp_paradise/connection/password.rb'
|
16
|
-
require 'ftp_paradise/connection/sync_ftp_object_onto_the_main_namespace.rb'
|
17
|
-
|
18
|
-
# ========================================================================= #
|
19
|
-
# === do_login
|
20
|
-
#
|
21
|
-
# This method is responsible for the login-action.
|
22
|
-
#
|
23
|
-
# The method signature for the net-ftp class' .login() is:
|
24
|
-
#
|
25
|
-
# login(user = "anonymous", passwd = nil, acct = nil)
|
26
|
-
#
|
27
|
-
# This method here accepts a Hash as first argument.
|
28
|
-
#
|
29
|
-
# For official information about .login(), see here:
|
30
|
-
#
|
31
|
-
# https://ruby-doc.org/stdlib/libdoc/net/ftp/rdoc/Net/FTP.html#method-i-login
|
32
|
-
#
|
33
|
-
# ========================================================================= #
|
34
|
-
def do_login(
|
35
|
-
to_this_url = nil, # The remote URL.
|
36
|
-
use_this_as_username = username?, # The login-name.
|
37
|
-
use_this_as_password = password?, # The password for that user.
|
38
|
-
be_verbose = be_verbose?
|
39
|
-
)
|
40
|
-
if to_this_url.nil?
|
41
|
-
to_this_url = FtpParadise.remote_url?
|
42
|
-
elsif to_this_url.is_a? Hash
|
43
|
-
end
|
44
|
-
# ======================================================================= #
|
45
|
-
# Rescue nil-passwords here.
|
46
|
-
# ======================================================================= #
|
47
|
-
if use_this_as_password.to_s.empty?
|
48
|
-
use_this_as_password = set_password(:try_to_use_a_default_password)
|
49
|
-
end
|
50
|
-
if be_verbose
|
51
|
-
# ===================================================================== #
|
52
|
-
# Display some info to the user here.
|
53
|
-
# ===================================================================== #
|
54
|
-
e; cliner
|
55
|
-
opnn; e "Using the URL #{royalblue(to_this_url)} (remote FTP host)."
|
56
|
-
e
|
57
|
-
e " Username: #{slateblue(use_this_as_username)}"
|
58
|
-
e " Password: #{slateblue(use_this_as_password)}"
|
59
|
-
e
|
60
|
-
report_transfer_mode_in_use
|
61
|
-
e
|
62
|
-
cliner
|
63
|
-
end
|
64
|
-
if ftp_object?.nil? and !to_this_url.nil?
|
65
|
-
initialize_a_new_net_ftp_object_with_this_url(to_this_url)
|
66
|
-
end
|
67
|
-
use_this_as_username = use_this_as_username.to_s
|
68
|
-
# ======================================================================= #
|
69
|
-
# The following code must be rescued because the login() method
|
70
|
-
# may fail in various ways.
|
71
|
-
# ======================================================================= #
|
72
|
-
begin
|
73
|
-
ftp_object?.login(
|
74
|
-
use_this_as_username,
|
75
|
-
use_this_as_password
|
76
|
-
)
|
77
|
-
# =================================================================== #
|
78
|
-
# Next, assign towards the toplevel reference to the ftp-connection.
|
79
|
-
# =================================================================== #
|
80
|
-
sync_ftp_object_onto_the_main_namespace if ftp_object?
|
81
|
-
if be_verbose and is_connected?
|
82
|
-
e
|
83
|
-
cliner {
|
84
|
-
e "- #{sfancy('Successfully')} logged into "\
|
85
|
-
"the remote FTP host at `#{simp(to_this_url)}`"
|
86
|
-
}
|
87
|
-
end
|
88
|
-
rescue Net::FTPPermError => error
|
89
|
-
opnn; e "We could not connect and login to `#{sfancy(to_this_url)}`."
|
90
|
-
opnn; e 'It may be that you lack the proper permissions.'
|
91
|
-
opnn; e 'This may happen because the user/password combination was'
|
92
|
-
opnn; e 'incorrect. User and password combination will be shown next:'
|
93
|
-
show_user_and_password
|
94
|
-
opnn; e "Feedbacking that error next, of class #{error.class.to_s}:"
|
95
|
-
opnn; e orange(error.to_s)
|
96
|
-
rescue Net::FTPConnectionError => error
|
97
|
-
opnn; e 'We do not seem to be connected. An error happened.'
|
98
|
-
pp error
|
99
|
-
pp error.class
|
100
|
-
end
|
101
|
-
end; alias do_connect do_login # === do_connect
|
102
|
-
alias connect_to do_login # === connect_to
|
103
|
-
alias connect do_login # === connect
|
104
|
-
alias login do_login # === login
|
105
|
-
alias login_to do_login # === login_to
|
106
|
-
alias reconnect do_login # === reconnect
|
107
|
-
|
108
|
-
end; end
|