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,90 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'ftp_paradise/interactive_ftp/reset.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module FtpParadise
|
8
|
+
|
9
|
+
class InteractiveFtp # === FtpParadise::InteractiveFtp
|
10
|
+
|
11
|
+
require 'ftp_paradise/interactive_ftp/misc.rb'
|
12
|
+
require 'ftp_paradise/interactive_ftp/readline.rb'
|
13
|
+
|
14
|
+
# ========================================================================= #
|
15
|
+
# === reset (reset tag)
|
16
|
+
#
|
17
|
+
# Initialize and/or reset the variables used in this class.
|
18
|
+
# ========================================================================= #
|
19
|
+
def reset
|
20
|
+
super()
|
21
|
+
# ======================================================================= #
|
22
|
+
# The following check is for my home system.
|
23
|
+
# ======================================================================= #
|
24
|
+
if File.exist? FILE_ROEBE_FTP
|
25
|
+
dataset = YAML.load_file(FILE_ROEBE_FTP)
|
26
|
+
determine_user_dataset_from_this_hash(dataset, :default)
|
27
|
+
end
|
28
|
+
# ======================================================================= #
|
29
|
+
# === @user_input
|
30
|
+
#
|
31
|
+
# Must "initialize" @user_input.
|
32
|
+
# ======================================================================= #
|
33
|
+
@user_input = nil
|
34
|
+
# ======================================================================= #
|
35
|
+
# Which files we did download so far.
|
36
|
+
# ======================================================================= #
|
37
|
+
@array_downloaded_files = []
|
38
|
+
# ======================================================================= #
|
39
|
+
# === @array_all_input
|
40
|
+
# ======================================================================= #
|
41
|
+
@array_all_input = [] # Stores which was the input.
|
42
|
+
# ======================================================================= #
|
43
|
+
# === @history
|
44
|
+
# ======================================================================= #
|
45
|
+
@history = []
|
46
|
+
# ======================================================================= #
|
47
|
+
# === @array_history_remote_directories
|
48
|
+
#
|
49
|
+
# This array keeps a listing of all remote directories we rcd-ed into.
|
50
|
+
# ======================================================================= #
|
51
|
+
@array_history_remote_directories = []
|
52
|
+
# ======================================================================= #
|
53
|
+
# === @debug
|
54
|
+
#
|
55
|
+
# Whether we will debug or not, by default.
|
56
|
+
# ======================================================================= #
|
57
|
+
@debug = SHALL_WE_DEBUG
|
58
|
+
# ======================================================================= #
|
59
|
+
# === @are_we_connected
|
60
|
+
# ======================================================================= #
|
61
|
+
@are_we_connected = false
|
62
|
+
# ======================================================================= #
|
63
|
+
# === @pad
|
64
|
+
# ======================================================================= #
|
65
|
+
@pad = ' ' # The default padding to use.
|
66
|
+
# ======================================================================= #
|
67
|
+
# === @use_readline
|
68
|
+
#
|
69
|
+
# Initially we will try to make use of the Readline module.
|
70
|
+
# ======================================================================= #
|
71
|
+
@use_readline = true
|
72
|
+
# ======================================================================= #
|
73
|
+
# === @use_this_editor
|
74
|
+
#
|
75
|
+
# Specify which editor we may use - this can be overruled in the
|
76
|
+
# interactive menu by the user of the FtpParadise project.
|
77
|
+
# ======================================================================= #
|
78
|
+
@use_this_editor = USE_THIS_EDITOR
|
79
|
+
# ======================================================================= #
|
80
|
+
# Try to make use of the Readline module as well.
|
81
|
+
# ======================================================================= #
|
82
|
+
consider_using_the_readline_module
|
83
|
+
reset_instance_variables_that_hold_all_arguments
|
84
|
+
set_file
|
85
|
+
set_local_directory
|
86
|
+
load_config
|
87
|
+
initialize_ftp_object # Initialize the @ftp variable.
|
88
|
+
end
|
89
|
+
|
90
|
+
end; end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'ftp_paradise/interactive_ftp/run.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module FtpParadise
|
8
|
+
|
9
|
+
class InteractiveFtp # === FtpParadise::InteractiveFtp
|
10
|
+
|
11
|
+
# ========================================================================= #
|
12
|
+
# === run
|
13
|
+
# ========================================================================= #
|
14
|
+
def run
|
15
|
+
set_passive :be_verbose
|
16
|
+
pass_commandline_arguments_into_the_menu # <- Must come before startup_actions().
|
17
|
+
startup_actions
|
18
|
+
do_login # Next, login.
|
19
|
+
enter_main_loop
|
20
|
+
end
|
21
|
+
|
22
|
+
end; end
|
@@ -0,0 +1,184 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'ftp_paradise/interactive_ftp/show.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module FtpParadise
|
8
|
+
|
9
|
+
class InteractiveFtp
|
10
|
+
|
11
|
+
# ========================================================================= #
|
12
|
+
# === show_remote_directories
|
13
|
+
# ========================================================================= #
|
14
|
+
def show_remote_directories
|
15
|
+
e "The remote directories at #{sdir(return_remote_pwd)} are:"
|
16
|
+
e
|
17
|
+
ftp?.return_remote_directories.each_with_index {|dir, index|
|
18
|
+
index += 1
|
19
|
+
e index.to_s.rjust(3)+') '+sdir(dir)
|
20
|
+
}
|
21
|
+
e
|
22
|
+
end
|
23
|
+
|
24
|
+
# ========================================================================= #
|
25
|
+
# === show_remote_files
|
26
|
+
#
|
27
|
+
# Use this method to show all remote files on a FTP site.
|
28
|
+
# ========================================================================= #
|
29
|
+
def show_remote_files(
|
30
|
+
mode = nil
|
31
|
+
) # Show the content of the remote host.
|
32
|
+
ftp?.show_remote_files
|
33
|
+
end
|
34
|
+
|
35
|
+
# ========================================================================= #
|
36
|
+
# === show_hosts
|
37
|
+
# ========================================================================= #
|
38
|
+
def show_hosts
|
39
|
+
e "The available hosts are:#{N}#{N}"
|
40
|
+
ftp?.array_available_hosts.each {|host|
|
41
|
+
e simp(" #{host}")
|
42
|
+
}; e
|
43
|
+
end
|
44
|
+
|
45
|
+
# ========================================================================= #
|
46
|
+
# === show_remote_listing
|
47
|
+
#
|
48
|
+
# This will display the remote file listing.
|
49
|
+
# ========================================================================= #
|
50
|
+
def show_remote_listing
|
51
|
+
ftp?.show_remote_listing
|
52
|
+
end
|
53
|
+
|
54
|
+
# ========================================================================= #
|
55
|
+
# === show_status
|
56
|
+
# ========================================================================= #
|
57
|
+
def show_status
|
58
|
+
cliner {
|
59
|
+
# e
|
60
|
+
# show_help # <- Disabled as of May 2017.
|
61
|
+
e
|
62
|
+
report_where_we_are_connected_to
|
63
|
+
report_remote_directory # Added Dec 2011.
|
64
|
+
report_local_dir
|
65
|
+
# debug_it
|
66
|
+
e
|
67
|
+
}
|
68
|
+
end
|
69
|
+
|
70
|
+
# ========================================================================= #
|
71
|
+
# === show_title
|
72
|
+
#
|
73
|
+
# Use this method to give us the title
|
74
|
+
# ========================================================================= #
|
75
|
+
def show_title
|
76
|
+
e return_title
|
77
|
+
end
|
78
|
+
|
79
|
+
# ========================================================================= #
|
80
|
+
# === show_history
|
81
|
+
#
|
82
|
+
# This method can be used to display the input-history of the user.
|
83
|
+
# ========================================================================= #
|
84
|
+
def show_history # History tag.
|
85
|
+
e "The history for #{sfancy(return_title)} is:"
|
86
|
+
@history.each_with_index { |key, index|
|
87
|
+
e '%3s' % (index+1).to_s+' '+key
|
88
|
+
}
|
89
|
+
end
|
90
|
+
|
91
|
+
# ========================================================================= #
|
92
|
+
# === show_which_files_we_did_download_so_far
|
93
|
+
# ========================================================================= #
|
94
|
+
def show_which_files_we_did_download_so_far
|
95
|
+
if @array_downloaded_files.empty?
|
96
|
+
e 'We did not yet download any file.'
|
97
|
+
else
|
98
|
+
e 'We downloaded these files so far:'
|
99
|
+
pp @array_downloaded_files
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
# ========================================================================= #
|
104
|
+
# === show_ftp_docu
|
105
|
+
#
|
106
|
+
# This method will show where to find ruby's ftp docu.
|
107
|
+
# ========================================================================= #
|
108
|
+
def show_ftp_docu
|
109
|
+
e
|
110
|
+
e ' https://www.ruby-doc.org/stdlib/libdoc/net/ftp/rdoc/Net/FTP.html'
|
111
|
+
e
|
112
|
+
end
|
113
|
+
|
114
|
+
# ========================================================================= #
|
115
|
+
# === show_ftp_yaml_file
|
116
|
+
# ========================================================================= #
|
117
|
+
def show_ftp_yaml_file
|
118
|
+
e 'The yaml file in question can be found at:'
|
119
|
+
e
|
120
|
+
e " #{sfile(FILE_ROEBE_FTP)}"
|
121
|
+
e
|
122
|
+
end
|
123
|
+
|
124
|
+
# ========================================================================= #
|
125
|
+
# === show_modtime_of
|
126
|
+
# ========================================================================= #
|
127
|
+
def show_modtime_of(i)
|
128
|
+
e "The modification time of #{sfile(i)} is:"
|
129
|
+
e
|
130
|
+
e ' '+sfancy(ftp?.modification_time_of?(i))
|
131
|
+
e
|
132
|
+
end
|
133
|
+
|
134
|
+
# ========================================================================= #
|
135
|
+
# === display_configuration_options (show config tag)
|
136
|
+
#
|
137
|
+
# This method will show the configuration settings.
|
138
|
+
#
|
139
|
+
# You can invoke this in an interactive FTP session by doing this:
|
140
|
+
#
|
141
|
+
# config?
|
142
|
+
#
|
143
|
+
# ========================================================================= #
|
144
|
+
def display_configuration_options # Config tag.
|
145
|
+
cliner {
|
146
|
+
if @file.to_s.empty?
|
147
|
+
e '@file is: unassigned as of yet'
|
148
|
+
else
|
149
|
+
e '@file is: '+sfancy(@file.to_s)
|
150
|
+
end
|
151
|
+
e '@local_directory is: '+sfancy(@local_directory.to_s)
|
152
|
+
e '@splitted is: '+sfancy(@splitted.to_s)
|
153
|
+
e 'Will we use the Readline module? '+
|
154
|
+
sfancy(verbose_truth(use_readline?))
|
155
|
+
e 'Will we show full names (with full path)? '+
|
156
|
+
sfancy(verbose_truth(show_full_names?))
|
157
|
+
e 'What is the base directory? '+
|
158
|
+
sfancy(@config.base_directory.to_s)
|
159
|
+
}
|
160
|
+
end
|
161
|
+
|
162
|
+
# ========================================================================= #
|
163
|
+
# === show_available_connections
|
164
|
+
# ========================================================================= #
|
165
|
+
def show_available_connections(
|
166
|
+
i = ARRAY_AVAILABLE_HOSTS
|
167
|
+
)
|
168
|
+
i.each_with_index {|entry, index|
|
169
|
+
e "#{index} #{entry}"
|
170
|
+
} if Object.const_defined? :RoebeFtpConstants
|
171
|
+
end
|
172
|
+
|
173
|
+
# ========================================================================= #
|
174
|
+
# === show_www_component
|
175
|
+
# ========================================================================= #
|
176
|
+
def show_www_component
|
177
|
+
e 'Make sure to visit:'
|
178
|
+
path = '$RSRC/ftp_paradise/lib/ftp_paradise/www/sinatra_web_interface.rb'
|
179
|
+
e " #{sfancy(path)}"
|
180
|
+
_ = get_env_of("ruby #{path}")
|
181
|
+
esystem _
|
182
|
+
end
|
183
|
+
|
184
|
+
end; end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'ftp_paradise/interactive_ftp/upload.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module FtpParadise
|
8
|
+
|
9
|
+
class InteractiveFtp # === FtpParadise::Interactive
|
10
|
+
|
11
|
+
# ========================================================================= #
|
12
|
+
# === upload (upload tag)
|
13
|
+
#
|
14
|
+
# Use this method to upload something locally to the remote site.
|
15
|
+
#
|
16
|
+
# You can also upload several files in one go - to do this, try
|
17
|
+
# one of these ways:
|
18
|
+
#
|
19
|
+
# upload 7,8 # This would upload file position 7 and 8.
|
20
|
+
# upload 1..293
|
21
|
+
#
|
22
|
+
# ========================================================================= #
|
23
|
+
def upload(
|
24
|
+
i = Dir['*']
|
25
|
+
)
|
26
|
+
# ======================================================================= #
|
27
|
+
# We will always work with an Array past the following point.
|
28
|
+
# ======================================================================= #
|
29
|
+
i = [i].flatten.compact # Safeguard against nil.
|
30
|
+
if i.empty?
|
31
|
+
i << @file if @file
|
32
|
+
end
|
33
|
+
i.map! {|entry|
|
34
|
+
if entry.include?('-') and !entry.include?('.') # Assume a range was given like 1-20.
|
35
|
+
splitted = entry.split('-')
|
36
|
+
entry = (splitted[0] .. splitted[1]).to_a
|
37
|
+
elsif entry.include?('..') # Assume a range such as: upload 1..25
|
38
|
+
entry =~ /(\d+)\.\.(\d+)/
|
39
|
+
start_position = $1.to_s.dup.to_i
|
40
|
+
end_position = $2.to_s.dup.to_i
|
41
|
+
entry = return_local_files[start_position, end_position]
|
42
|
+
elsif entry.include?(',')
|
43
|
+
splitted = i.split(',')
|
44
|
+
entry = (splitted[0] .. splitted[1]).to_a
|
45
|
+
elsif (entry == 'ALL') or (entry == '*')
|
46
|
+
entry = Dir['*']
|
47
|
+
elsif entry.include?('*.') or entry.include?('*')
|
48
|
+
entry = Dir[entry]
|
49
|
+
end
|
50
|
+
entry
|
51
|
+
}
|
52
|
+
i.flatten!
|
53
|
+
i.compact!
|
54
|
+
if on_roebe? and !is_connected?
|
55
|
+
connect_to :shevy
|
56
|
+
end
|
57
|
+
i.each {|this_file|
|
58
|
+
if this_file =~ /^\d+$/ # upload only a specific number.
|
59
|
+
sorted = Dir['*'].sort
|
60
|
+
if i.is_a? Array
|
61
|
+
i = i.first
|
62
|
+
end
|
63
|
+
this_file = sorted[i.to_i - 1]
|
64
|
+
end
|
65
|
+
_ = this_file # default to upload to 'all'
|
66
|
+
if File.exist?(_)
|
67
|
+
# =================================================================== #
|
68
|
+
# Next, some files will always be in binary mode. These are
|
69
|
+
# defined in the Array ARRAY_BINARY_FILES.
|
70
|
+
# =================================================================== #
|
71
|
+
if ARRAY_BINARY_FILES.include?(File.extname(_).delete('.')) and
|
72
|
+
(@mode != :binary)
|
73
|
+
use_binary_mode
|
74
|
+
end
|
75
|
+
case @mode
|
76
|
+
when :ascii
|
77
|
+
set_file(_)
|
78
|
+
ftp?.upload(_) # And now, call the functionality in the FTP lib.
|
79
|
+
else
|
80
|
+
ftp?.upload_binary(_)
|
81
|
+
end
|
82
|
+
else
|
83
|
+
opne swarn('But the file `')+
|
84
|
+
sfile(i)+
|
85
|
+
swarn('` does not exist.')
|
86
|
+
end
|
87
|
+
}
|
88
|
+
end
|
89
|
+
|
90
|
+
end; end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'ftp_paradise/interactive_ftp/user_input.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module FtpParadise
|
8
|
+
|
9
|
+
class InteractiveFtp # === FtpParadise::InteractiveFtp
|
10
|
+
|
11
|
+
# ========================================================================= #
|
12
|
+
# === obtain_user_input
|
13
|
+
#
|
14
|
+
# This method will obtain user input, and assign it to the variable
|
15
|
+
# @user_input.
|
16
|
+
# ========================================================================= #
|
17
|
+
def obtain_user_input
|
18
|
+
if @use_readline
|
19
|
+
user_input = Readline.readline('', true)
|
20
|
+
Readline::HISTORY.pop if user_input.strip.empty?
|
21
|
+
else
|
22
|
+
user_input = $stdin.gets.chomp
|
23
|
+
end
|
24
|
+
# ======================================================================= #
|
25
|
+
# Get rid of potential '#' comments in the input.
|
26
|
+
# ======================================================================= #
|
27
|
+
if user_input.include? '#'
|
28
|
+
user_input = user_input[0 .. user_input.index('#')-1]
|
29
|
+
end
|
30
|
+
user_input.strip! # Get rid of ' ' empty characters.
|
31
|
+
_ = user_input
|
32
|
+
unless _.empty? # append to history.
|
33
|
+
try_to_append_this_to_the_history(_)
|
34
|
+
end
|
35
|
+
# ======================================================================= #
|
36
|
+
# If the user did input a ';' character then we will assume that he
|
37
|
+
# wants to send multiple commands. We will however NOT assume so
|
38
|
+
# if the string also includes a 'http://' - in that case, we assume
|
39
|
+
# a HTTP URL instead.
|
40
|
+
# ======================================================================= #
|
41
|
+
if user_input.include? ';' and !user_input.include?('http://')
|
42
|
+
user_input = user_input.split(';')
|
43
|
+
else
|
44
|
+
user_input = [user_input] # In this case simply turn it into an Array.
|
45
|
+
end
|
46
|
+
# ======================================================================= #
|
47
|
+
# The @user_input variable should always be an Array.
|
48
|
+
# ======================================================================= #
|
49
|
+
@user_input = user_input
|
50
|
+
end; alias get_user_input obtain_user_input # === get_user_input
|
51
|
+
alias fetch_user_input obtain_user_input # === fetch_user_input
|
52
|
+
|
53
|
+
end; end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen-string-literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'ftp_paradise/project/project.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module FtpParadise
|
8
|
+
|
9
|
+
_ = File.absolute_path("#{__dir__}/..")+'/'
|
10
|
+
|
11
|
+
# ========================================================================= #
|
12
|
+
# === PROJECT_BASE_DIRECTORY
|
13
|
+
# ========================================================================= #
|
14
|
+
begin # We need to make it failsafe.
|
15
|
+
PROJECT_BASE_DIRECTORY = (
|
16
|
+
File.realpath(_)+'/'
|
17
|
+
).squeeze '/'
|
18
|
+
rescue
|
19
|
+
puts 'An error happened. We will hardcode the constant towards -> '+_
|
20
|
+
PROJECT_BASE_DIRECTORY = # Else default to my directory.
|
21
|
+
'/home/x/DATA/PROGRAMMING_LANGUAGES/RUBY/src/'\
|
22
|
+
'ftp_paradise/lib/ftp_paradise/'
|
23
|
+
end
|
24
|
+
|
25
|
+
# ========================================================================= #
|
26
|
+
# === FtpParadise.project_base_dir?
|
27
|
+
# ========================================================================= #
|
28
|
+
def self.project_base_dir?
|
29
|
+
PROJECT_BASE_DIRECTORY
|
30
|
+
end
|
31
|
+
|
32
|
+
# ========================================================================= #
|
33
|
+
# === PROJECT_YAML_DIRECTORY
|
34
|
+
#
|
35
|
+
# This constant specifies where the project-specific yaml/ directory
|
36
|
+
# will be kept at for the ftp_paradise project. Ideally you should
|
37
|
+
# use the method rather than this constant, though.
|
38
|
+
# ========================================================================= #
|
39
|
+
PROJECT_YAML_DIRECTORY = "#{PROJECT_BASE_DIRECTORY}yaml/"
|
40
|
+
YAML_DIRECTORY = PROJECT_YAML_DIRECTORY
|
41
|
+
|
42
|
+
# ========================================================================= #
|
43
|
+
# === FtpParadise.project_yaml_dir?
|
44
|
+
#
|
45
|
+
# This method here must be defined before FtpParadise.initialize()
|
46
|
+
# is to be invoked.
|
47
|
+
# ========================================================================= #
|
48
|
+
def self.project_yaml_dir?
|
49
|
+
"#{PROJECT_BASE_DIRECTORY}yaml/"
|
50
|
+
end; self.instance_eval { alias yaml_directory? project_yaml_dir? } # === FtpParadise.yaml_directory?
|
51
|
+
|
52
|
+
# ========================================================================= #
|
53
|
+
# === yaml_directory?
|
54
|
+
# ========================================================================= #
|
55
|
+
def yaml_directory?
|
56
|
+
FtpParadise.yaml_directory?
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
if __FILE__ == $PROGRAM_NAME
|
62
|
+
pp FtpParadise.project_base_dir?
|
63
|
+
pp FtpParadise.project_yaml_dir?
|
64
|
+
end
|