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
Binary file
|
@@ -0,0 +1,103 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# All constants for class Interactive shall be stored in this file here.
|
6
|
+
# =========================================================================== #
|
7
|
+
# require 'ftp_paradise/interactive_ftp/constants.rb'
|
8
|
+
# =========================================================================== #
|
9
|
+
module FtpParadise
|
10
|
+
|
11
|
+
class InteractiveFtp # === FtpParadise::InteractiveFtp
|
12
|
+
|
13
|
+
require 'ftp_paradise/toplevel_methods/rds.rb'
|
14
|
+
|
15
|
+
# ========================================================================= #
|
16
|
+
# === NAMESPACE
|
17
|
+
# ========================================================================= #
|
18
|
+
NAMESPACE = inspect
|
19
|
+
|
20
|
+
# ========================================================================= #
|
21
|
+
# === TITLE
|
22
|
+
# ========================================================================= #
|
23
|
+
TITLE = 'Interactive FTP'
|
24
|
+
|
25
|
+
# ========================================================================= #
|
26
|
+
# === SHOW_REMOTE_FILES_UPON_SUCCESSFUL_LOGIN
|
27
|
+
#
|
28
|
+
# If this constant is true then we will show the remote file
|
29
|
+
# listing upon a successful (first) login action.
|
30
|
+
# ========================================================================= #
|
31
|
+
SHOW_REMOTE_FILES_UPON_SUCCESSFUL_LOGIN = false
|
32
|
+
|
33
|
+
# ========================================================================= #
|
34
|
+
# === SHALL_WE_DEBUG
|
35
|
+
# ========================================================================= #
|
36
|
+
SHALL_WE_DEBUG = true
|
37
|
+
|
38
|
+
# ========================================================================= #
|
39
|
+
# === PROMPT_TO_USE
|
40
|
+
#
|
41
|
+
# Which Prompt to use by default for the Interactive FTP component.
|
42
|
+
# ========================================================================= #
|
43
|
+
PROMPT_TO_USE = '> '
|
44
|
+
|
45
|
+
# ========================================================================= #
|
46
|
+
# === ARRAY_FORBIDDEN_HISTORY_COMMANDS
|
47
|
+
# ========================================================================= #
|
48
|
+
ARRAY_FORBIDDEN_HISTORY_COMMANDS = %w(
|
49
|
+
last
|
50
|
+
) # Dont append last to the history.
|
51
|
+
|
52
|
+
# ========================================================================= #
|
53
|
+
# === OPEN_IN_DEFAULT_EDITOR
|
54
|
+
# ========================================================================= #
|
55
|
+
OPEN_IN_DEFAULT_EDITOR = true
|
56
|
+
|
57
|
+
# ========================================================================= #
|
58
|
+
# === USE_THIS_EDITOR
|
59
|
+
# ========================================================================= #
|
60
|
+
USE_THIS_EDITOR = ENV['EDITOR'].to_s
|
61
|
+
|
62
|
+
# ========================================================================= #
|
63
|
+
# === DEFAULT_LOCAL_DIRECTORY
|
64
|
+
# ========================================================================= #
|
65
|
+
DEFAULT_LOCAL_DIRECTORY = ::FtpParadise.rds("#{Dir.pwd}/") # More flexible that way, I suppose.
|
66
|
+
|
67
|
+
# ========================================================================= #
|
68
|
+
# === NAME_OF_THIS_FILE
|
69
|
+
# ========================================================================= #
|
70
|
+
NAME_OF_THIS_FILE = "#{PROJECT_BASE_DIRECTORY}interactive_ftp.rb"
|
71
|
+
|
72
|
+
# ========================================================================= #
|
73
|
+
# === ARRAY_PROJECT_FILES
|
74
|
+
#
|
75
|
+
# The following files have to be opened when you wish to open the
|
76
|
+
# project files.
|
77
|
+
# ========================================================================= #
|
78
|
+
ARRAY_PROJECT_FILES = %w(
|
79
|
+
library.rb
|
80
|
+
interactive.rb
|
81
|
+
addon/constants/roebe_ftp_constants.rb
|
82
|
+
doc/TODO
|
83
|
+
).map {|entry| PROJECT_BASE_DIRECTORY+entry}
|
84
|
+
|
85
|
+
# ========================================================================= #
|
86
|
+
# === DEFAULT_REMOTE_DIRECTORY
|
87
|
+
#
|
88
|
+
# The default remote directory.
|
89
|
+
# ========================================================================= #
|
90
|
+
DEFAULT_REMOTE_DIRECTORY = %q(
|
91
|
+
htdocs
|
92
|
+
).delete("\n").strip # kill newlines and empty spaces.
|
93
|
+
|
94
|
+
# ========================================================================= #
|
95
|
+
# === DEFAULT_REMOTE_FILE
|
96
|
+
#
|
97
|
+
# The default remote file comes next.
|
98
|
+
# ========================================================================= #
|
99
|
+
DEFAULT_REMOTE_FILE = %q(
|
100
|
+
README.md
|
101
|
+
).gsub(/\n/,'').strip
|
102
|
+
|
103
|
+
end; end
|
@@ -0,0 +1,216 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'ftp_paradise/interactive_ftp/directory_handling.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module FtpParadise
|
8
|
+
|
9
|
+
class InteractiveFtp
|
10
|
+
|
11
|
+
# ========================================================================= #
|
12
|
+
# === ftp_remote_directory?
|
13
|
+
# ========================================================================= #
|
14
|
+
def ftp_remote_directory?
|
15
|
+
ftp?.remote_directory?
|
16
|
+
end; alias return_remote_pwd ftp_remote_directory? # === return_remote_pwd
|
17
|
+
|
18
|
+
# ========================================================================= #
|
19
|
+
# === report_remote_directory
|
20
|
+
#
|
21
|
+
# This method will report the remote directory.
|
22
|
+
# ========================================================================= #
|
23
|
+
def report_remote_directory(
|
24
|
+
make_newline = true
|
25
|
+
)
|
26
|
+
if is_connected?
|
27
|
+
remote_dir = sdir(ftp_remote_directory?)
|
28
|
+
if make_newline
|
29
|
+
e 'The remote directory is: '
|
30
|
+
e " #{sdir(remote_dir)}"
|
31
|
+
else
|
32
|
+
e 'The remote directory is: '+sdir(remote_dir)
|
33
|
+
end
|
34
|
+
else
|
35
|
+
e 'No connection is available. You may have to re-connect again.'
|
36
|
+
end
|
37
|
+
end; alias show_remote_directory report_remote_directory # === show_remote_directory
|
38
|
+
|
39
|
+
# ========================================================================= #
|
40
|
+
# === remote_directory?
|
41
|
+
# ========================================================================= #
|
42
|
+
def remote_directory?
|
43
|
+
@remote_directory
|
44
|
+
end
|
45
|
+
|
46
|
+
# ========================================================================= #
|
47
|
+
# === set_remote_directory
|
48
|
+
# ========================================================================= #
|
49
|
+
def set_remote_directory(i)
|
50
|
+
i = File.dirname(i) if ftp?.is_file?(i) # Get the base directory here.
|
51
|
+
@remote_directory = i
|
52
|
+
@array_history_remote_directories << @remote_directory
|
53
|
+
end
|
54
|
+
|
55
|
+
# ========================================================================= #
|
56
|
+
# === upload_directory
|
57
|
+
# ========================================================================= #
|
58
|
+
def upload_directory(i)
|
59
|
+
ftp?.upload_directory(i)
|
60
|
+
end
|
61
|
+
|
62
|
+
# ========================================================================= #
|
63
|
+
# === remote_change_directory
|
64
|
+
#
|
65
|
+
# This method can be used to change directory on the remote host.
|
66
|
+
#
|
67
|
+
# An argument such as :show_remote_file_listing can be passed as second
|
68
|
+
# argument to this method, in which case we will list the content of
|
69
|
+
# the remote directory after the cd-action.
|
70
|
+
#
|
71
|
+
# If readline is used, as determined by the instance variable @use_readline,
|
72
|
+
# then we will attempt to cd-<TAB>.
|
73
|
+
#
|
74
|
+
# Invocation example:
|
75
|
+
#
|
76
|
+
# rcd htdocs
|
77
|
+
#
|
78
|
+
# ========================================================================= #
|
79
|
+
def remote_change_directory(
|
80
|
+
i = f?,
|
81
|
+
optional_instruction = nil,
|
82
|
+
be_verbose = false
|
83
|
+
)
|
84
|
+
i = i.first if i.is_a? Array
|
85
|
+
i = '..' if i.nil? # <- Tiny "safeguard".
|
86
|
+
# ======================================================================= #
|
87
|
+
# We must first check whether we input only numbers,
|
88
|
+
# and whether such a directory does NOT exist.
|
89
|
+
# ======================================================================= #
|
90
|
+
if (i =~ /^\d+$/) and !is_dir?(i)
|
91
|
+
ftp?.update_file_listing
|
92
|
+
i = ftp?.array_file_listing[i.to_i - 1]
|
93
|
+
end
|
94
|
+
if be_verbose
|
95
|
+
e "Trying to cd into the remote directory `#{sfancy(i)}`."
|
96
|
+
end
|
97
|
+
case i # case tag
|
98
|
+
when '?' # intercept ?
|
99
|
+
e 'You went into these remote directories so far:'
|
100
|
+
@array_history_remote_directories.each { |entry|
|
101
|
+
e "- #{entry}"
|
102
|
+
}
|
103
|
+
else # This is the default.
|
104
|
+
if i
|
105
|
+
i.squeeze!('/') if i.include? '//' # Get rid of multiple //.
|
106
|
+
e "Changing remote directory to `#{sdir(i)}` now."
|
107
|
+
end
|
108
|
+
begin
|
109
|
+
ftp?.chdir(i)
|
110
|
+
set_remote_directory(i)
|
111
|
+
if optional_instruction
|
112
|
+
case optional_instruction
|
113
|
+
when :show_remote_file_listing
|
114
|
+
show_remote_files
|
115
|
+
end
|
116
|
+
end
|
117
|
+
rescue Exception => error
|
118
|
+
pp error
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end; alias remote_cd remote_change_directory # === remote_cd
|
122
|
+
|
123
|
+
# ========================================================================= #
|
124
|
+
# === change_local_and_remote_directories
|
125
|
+
#
|
126
|
+
# We combine local cd and remote cd here.
|
127
|
+
# ========================================================================= #
|
128
|
+
def change_local_and_remote_directories(
|
129
|
+
target = DEFAULT_LOCAL_DIRECTORY
|
130
|
+
)
|
131
|
+
change_directory(target, :be_silent) # Mandatory since as of 01.05.2011
|
132
|
+
if are_we_connected?
|
133
|
+
remote_change_directory(target) # Since as of August 2011.
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
# ========================================================================= #
|
138
|
+
# === set_start_directory=
|
139
|
+
# ========================================================================= #
|
140
|
+
def set_start_directory=(i) # set_start_directory=(i)
|
141
|
+
change_directory(i)
|
142
|
+
end
|
143
|
+
|
144
|
+
# ========================================================================= #
|
145
|
+
# === change_directory (cd tag)
|
146
|
+
#
|
147
|
+
# This only changes for local directories, not remote directories.
|
148
|
+
# ========================================================================= #
|
149
|
+
def change_directory(
|
150
|
+
i = DEFAULT_LOCAL_DIRECTORY,
|
151
|
+
be_verbose = true
|
152
|
+
)
|
153
|
+
i = '..' if i.nil?
|
154
|
+
be_verbose = false if be_verbose == :be_silent
|
155
|
+
i = i.to_s
|
156
|
+
i.gsub!(/; pwd/,'') if i.include? '; pwd'
|
157
|
+
begin
|
158
|
+
i = get_env_of(i) if i.include? '$'
|
159
|
+
if File.exist?(i)
|
160
|
+
# =================================================================== #
|
161
|
+
# Next, do the actual "change directory" action.
|
162
|
+
# =================================================================== #
|
163
|
+
Dir.chdir(i) # This will cd for local directories.
|
164
|
+
i = return_pwd if i == '..'
|
165
|
+
i = rds(return_pwd) unless i.include? '/'
|
166
|
+
set_local_directory(i) # Set the new pwd here.
|
167
|
+
report_local_directory if be_verbose
|
168
|
+
else # else, the directory does not exist.
|
169
|
+
e swarn('But the directory '+sdir(i)+' does not exist '\
|
170
|
+
'locally in '+sdir(return_pwd)+'.')
|
171
|
+
end
|
172
|
+
rescue Exception => error
|
173
|
+
e 'An exception occurred in '+swarn('change_directory()')
|
174
|
+
e "The directory `#{sdir(i)}` does not exist."
|
175
|
+
pp error # Should remove this and error perhaps.
|
176
|
+
end
|
177
|
+
end; alias cd change_directory # === cd
|
178
|
+
|
179
|
+
# ========================================================================= #
|
180
|
+
# === report_local_directory
|
181
|
+
#
|
182
|
+
# Use only this method when reporting the local directory.
|
183
|
+
# ========================================================================= #
|
184
|
+
def report_local_directory
|
185
|
+
e 'The local directory is: '+N+
|
186
|
+
@pad+sdir(return_pwd)
|
187
|
+
end; alias report_local_dir report_local_directory # === report_local_dir
|
188
|
+
|
189
|
+
# ========================================================================= #
|
190
|
+
# === remote_create_directory
|
191
|
+
# ========================================================================= #
|
192
|
+
def remote_create_directory(
|
193
|
+
i = a?,
|
194
|
+
be_verbose = true
|
195
|
+
)
|
196
|
+
if i.is_a? Array
|
197
|
+
i.each {|entry| remote_create_directory(entry, be_verbose) }
|
198
|
+
else
|
199
|
+
# ===================================================================== #
|
200
|
+
# Delegate towards the respective module-method next.
|
201
|
+
# ===================================================================== #
|
202
|
+
if be_verbose
|
203
|
+
e "Creating the directory #{sdir(i)} next:"
|
204
|
+
end
|
205
|
+
FtpParadise.remote_create_directory(i, @ftp)
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
# ========================================================================= #
|
210
|
+
# === return_pwd
|
211
|
+
# ========================================================================= #
|
212
|
+
def return_pwd
|
213
|
+
("#{Dir.pwd}/").squeeze '/'
|
214
|
+
end
|
215
|
+
|
216
|
+
end; end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'ftp_paradise/interactive_ftp/help.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module FtpParadise
|
8
|
+
|
9
|
+
class InteractiveFtp
|
10
|
+
|
11
|
+
# ========================================================================= #
|
12
|
+
# === show_help (help tag)
|
13
|
+
# ========================================================================= #
|
14
|
+
def show_help
|
15
|
+
cliner
|
16
|
+
e "Try one of these #{sfancy('help options')} for interactive-ftp:#{N}#{N}"
|
17
|
+
e parens(:assign)+' '+pound_token+'Assign to the @file variable'
|
18
|
+
e parens(:help)+' '+pound_token+'To see the help section'
|
19
|
+
e parens(:history)+' '+pound_token+'To show the history'
|
20
|
+
e parens(:cd)+' '+pound_token+'Change local directory'
|
21
|
+
e parens(:config)+' '+pound_token+'Show the configuration'
|
22
|
+
e parens(:dated)+' '+pound_token+'Display the remote directory '\
|
23
|
+
'content in a time-sorted manner'
|
24
|
+
e parens(:edit)+' '+pound_token+'Edit this file here in your main editor'
|
25
|
+
e parens(:everything)+' '+pound_token+'Show everything (username, password, host and so on)'
|
26
|
+
e parens(:login)+' '+pound_token+'Connect to the remote host (alias '\
|
27
|
+
'to connect_to exists)'
|
28
|
+
e parens(:list)+' '+pound_token+'List remote files'
|
29
|
+
e parens(:last)+' '+pound_token+'Repeat the last action (or show the last action)'
|
30
|
+
e parens(:rcd)+' '+pound_token+'Change remote directory'
|
31
|
+
e parens(:remote?)+' '+pound_token+'List where we are connected'
|
32
|
+
e parens(:stat)+' '+pound_token+'Show information about a file'
|
33
|
+
e parens(:status?)+' '+pound_token+'See the current status of the connection'
|
34
|
+
e parens(:file?)+' '+pound_token+'Shows whether we have a '+
|
35
|
+
'default file set (which can be used to upload)'
|
36
|
+
e parens(:info)+' '+pound_token+'Shows some information (debug)'
|
37
|
+
e parens(:set_port)+' '+pound_token+'Set the port number'
|
38
|
+
e parens(:q)+' '+pound_token+'To quit/exit'
|
39
|
+
e parens(:quit)+' '+pound_token+'Quit the session'
|
40
|
+
if on_roebe? # Display it only for me.
|
41
|
+
e parens(:shevy)+' '+pound_token+'Connect to shevy'
|
42
|
+
end
|
43
|
+
e parens(:lpwd)+' '+pound_token+'Report the current remote directory'
|
44
|
+
e parens(:pwd)+' '+pound_token+'Report the local directory'+N
|
45
|
+
e parens(:welcome)+' '+pound_token+'Show the welcome-message of the remote FTP server'+N
|
46
|
+
e
|
47
|
+
cliner
|
48
|
+
end; alias show_help_options show_help # === show_help_options
|
49
|
+
|
50
|
+
end; end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'ftp_paradise/interactive_ftp/initialize.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module FtpParadise
|
8
|
+
|
9
|
+
class InteractiveFtp
|
10
|
+
|
11
|
+
# ========================================================================= #
|
12
|
+
# === initialize
|
13
|
+
# ========================================================================= #
|
14
|
+
def initialize(
|
15
|
+
optional_commandline_arguments = nil,
|
16
|
+
run_already = true
|
17
|
+
)
|
18
|
+
register_sigint
|
19
|
+
reset
|
20
|
+
set_commandline_arguments(
|
21
|
+
optional_commandline_arguments
|
22
|
+
)
|
23
|
+
set_run_mode(:standalone) # Purposely defined before run(). This way, we can change it.
|
24
|
+
run if run_already
|
25
|
+
end
|
26
|
+
|
27
|
+
end; end
|
@@ -0,0 +1,998 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# === FtpParadise::InteractiveFtp
|
6
|
+
#
|
7
|
+
# Use this class here for interactive usage of the FTP paradise project.
|
8
|
+
#
|
9
|
+
# This class provides a commandline variant of the FtpParadise project,
|
10
|
+
# which allows you to interactively issue commands and instructions
|
11
|
+
# to a remote FTP server.
|
12
|
+
#
|
13
|
+
# No GUI code is otherwise stored herein.
|
14
|
+
# =========================================================================== #
|
15
|
+
# The official source for Ruby-FTP can be found at:
|
16
|
+
#
|
17
|
+
# http://www.ruby-doc.org/stdlib/libdoc/net/ftp/rdoc/Net/FTP.html
|
18
|
+
#
|
19
|
+
# Usage example for this class here:
|
20
|
+
#
|
21
|
+
# FtpParadise::InteractiveFtp.new
|
22
|
+
# FtpParadise.interactive
|
23
|
+
#
|
24
|
+
# =========================================================================== #
|
25
|
+
# require 'ftp_paradise/interactive_ftp/interactive_ftp.rb'
|
26
|
+
# =========================================================================== #
|
27
|
+
require 'ftp_paradise/requires/common_basic_requires.rb'
|
28
|
+
require 'ftp_paradise/base/prototype.rb'
|
29
|
+
require 'ftp_paradise/toplevel_methods/data.rb'
|
30
|
+
require 'ftp_paradise/toplevel_methods/ftp_object.rb'
|
31
|
+
require 'ftp_paradise/toplevel_methods/login_name.rb'
|
32
|
+
require 'ftp_paradise/toplevel_methods/password.rb'
|
33
|
+
require 'ftp_paradise/toplevel_methods/remote_url.rb'
|
34
|
+
# =========================================================================== #
|
35
|
+
# Next ftp_connection/ files:
|
36
|
+
# =========================================================================== #
|
37
|
+
require 'ftp_paradise/connection/connection.rb'
|
38
|
+
require 'ftp_paradise/base/prototype.rb'
|
39
|
+
|
40
|
+
module FtpParadise
|
41
|
+
|
42
|
+
class InteractiveFtp # === FtpParadise::InteractiveFtp
|
43
|
+
|
44
|
+
include ::FtpParadise::Base
|
45
|
+
|
46
|
+
# ========================================================================= #
|
47
|
+
# Next, load up interactive_ftp-specific .rb files:
|
48
|
+
# ========================================================================= #
|
49
|
+
require 'ftp_paradise/interactive_ftp/constants.rb'
|
50
|
+
require 'ftp_paradise/interactive_ftp/help.rb'
|
51
|
+
require 'ftp_paradise/interactive_ftp/initialize.rb'
|
52
|
+
require 'ftp_paradise/interactive_ftp/main_loop.rb'
|
53
|
+
require 'ftp_paradise/interactive_ftp/menu.rb'
|
54
|
+
require 'ftp_paradise/interactive_ftp/misc.rb'
|
55
|
+
require 'ftp_paradise/interactive_ftp/mode.rb'
|
56
|
+
require 'ftp_paradise/interactive_ftp/remove.rb'
|
57
|
+
require 'ftp_paradise/interactive_ftp/reset.rb'
|
58
|
+
require 'ftp_paradise/interactive_ftp/run.rb'
|
59
|
+
require 'ftp_paradise/interactive_ftp/show.rb'
|
60
|
+
require 'ftp_paradise/interactive_ftp/upload.rb'
|
61
|
+
require 'ftp_paradise/interactive_ftp/user_input.rb'
|
62
|
+
|
63
|
+
begin
|
64
|
+
require 'rcfiles'
|
65
|
+
rescue LoadError; end
|
66
|
+
|
67
|
+
# ========================================================================= #
|
68
|
+
# === verbose_truth
|
69
|
+
# ========================================================================= #
|
70
|
+
def verbose_truth(i = '')
|
71
|
+
VerboseTruth[i]
|
72
|
+
end
|
73
|
+
|
74
|
+
# ========================================================================= #
|
75
|
+
# === set_url
|
76
|
+
# ========================================================================= #
|
77
|
+
def set_url(i)
|
78
|
+
::FtpParadise.set_remote_host(i)
|
79
|
+
end
|
80
|
+
|
81
|
+
# ========================================================================= #
|
82
|
+
# === ftp?
|
83
|
+
# ========================================================================= #
|
84
|
+
def ftp?
|
85
|
+
FtpParadise.ftp_object?
|
86
|
+
end; alias ftp_object? ftp? # === ftp_object?
|
87
|
+
|
88
|
+
# ========================================================================= #
|
89
|
+
# === connected_to?
|
90
|
+
#
|
91
|
+
# Feedback where we are connected to.
|
92
|
+
# ========================================================================= #
|
93
|
+
def connected_to?
|
94
|
+
if ftp?.open?
|
95
|
+
report_where_we_are_connected_to
|
96
|
+
report_remote_directory # Added Dec 2011.
|
97
|
+
# report_local_dir
|
98
|
+
# unless ftp?.empty?
|
99
|
+
# e 'The remote file listing is:'
|
100
|
+
# show_remote_listing
|
101
|
+
# end # Disabled the above chunk as of Apr 2017.
|
102
|
+
else
|
103
|
+
e 'We are not connected to any remote FTP server currently.'
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
# ========================================================================= #
|
108
|
+
# === initialize_ftp_object (reset tag)
|
109
|
+
#
|
110
|
+
# The FTP Subsection is gathered here. This method is called from
|
111
|
+
# the method reset().
|
112
|
+
# ========================================================================= #
|
113
|
+
def initialize_ftp_object
|
114
|
+
FtpParadise.use_this_as_ftp_object(
|
115
|
+
FtpParadise::Connection.new(:default, false)
|
116
|
+
)
|
117
|
+
ftp?.enable_debug if debug? # Set the @debug variable inside of @ftp to true.
|
118
|
+
set_passive
|
119
|
+
use_ascii_mode
|
120
|
+
end
|
121
|
+
|
122
|
+
# ========================================================================= #
|
123
|
+
# === f?
|
124
|
+
# ========================================================================= #
|
125
|
+
def f?
|
126
|
+
@first_argument # First argument. Keep in mind that the second argument is stored in @s.
|
127
|
+
end; alias f f? # === f
|
128
|
+
|
129
|
+
# ========================================================================= #
|
130
|
+
# === connect_to_this_remote_url
|
131
|
+
# ========================================================================= #
|
132
|
+
def connect_to_this_remote_url(
|
133
|
+
i = remote_url?,
|
134
|
+
be_verbose = :be_verbose
|
135
|
+
)
|
136
|
+
case be_verbose
|
137
|
+
when :be_verbose
|
138
|
+
be_verbose = true
|
139
|
+
end
|
140
|
+
if be_verbose
|
141
|
+
e "Connecting to this remote URL: #{sfancy(i)}"
|
142
|
+
end
|
143
|
+
FtpParadise.use_this_as_ftp_object(
|
144
|
+
FtpParadise::Connection.new(i)
|
145
|
+
)
|
146
|
+
ftp?.login(
|
147
|
+
FtpParadise.login_name?,
|
148
|
+
password?
|
149
|
+
)
|
150
|
+
end
|
151
|
+
|
152
|
+
# ========================================================================= #
|
153
|
+
# === rename
|
154
|
+
#
|
155
|
+
# This will attempt a remote rename-action.
|
156
|
+
# ========================================================================= #
|
157
|
+
def rename(a, b)
|
158
|
+
begin
|
159
|
+
a = convert_number_to_file(a)
|
160
|
+
ftp?.rename(a, b)
|
161
|
+
rescue Net::FTPPermError
|
162
|
+
e "The file at #{sfile(i)} does not seem to exist - thus, "\
|
163
|
+
"we can not rename it."
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
# ========================================================================= #
|
168
|
+
# === upload_this_file
|
169
|
+
# ========================================================================= #
|
170
|
+
def upload_this_file(
|
171
|
+
i = f?
|
172
|
+
)
|
173
|
+
if i.is_a? Array
|
174
|
+
i.each {|entry| upload_this_file(entry) }
|
175
|
+
else
|
176
|
+
e 'Trying to upload this file `'+sfile(i)+'` next:'
|
177
|
+
ftp?.puttextfile(i)
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
# ========================================================================= #
|
182
|
+
# === reset_instance_variables_that_hold_all_arguments
|
183
|
+
#
|
184
|
+
# Use this method to initialite the instance variables that will hold
|
185
|
+
# the arguments to methods, from the user input.
|
186
|
+
#
|
187
|
+
# @s refers to the second argument.
|
188
|
+
# ========================================================================= #
|
189
|
+
def reset_instance_variables_that_hold_all_arguments
|
190
|
+
@splitted = @s = @first_argument = @all_arguments = nil
|
191
|
+
end
|
192
|
+
|
193
|
+
# ========================================================================= #
|
194
|
+
# === set_file
|
195
|
+
# ========================================================================= #
|
196
|
+
def set_file(i = nil) # Use only this to set @file variable.
|
197
|
+
if i # Safeguard against nil.
|
198
|
+
i = i.first if i.is_a? Array
|
199
|
+
i = i.to_s
|
200
|
+
i = Dir.pwd+'/'+i if ! i.include?('/') # Since Dec 2011 we try to use only the absolute path.
|
201
|
+
unless File.exist?(i)
|
202
|
+
i << '.c' unless i.include? '.' # Append .c to files, unless the file exists.
|
203
|
+
end
|
204
|
+
i = FtpParadise.rds(i)
|
205
|
+
end
|
206
|
+
@file = i # This is the only allowed way to modify @file.
|
207
|
+
end
|
208
|
+
|
209
|
+
# ========================================================================= #
|
210
|
+
# === be_verbose=
|
211
|
+
# ========================================================================= #
|
212
|
+
def be_verbose=(i)
|
213
|
+
@be_verbose = i
|
214
|
+
end
|
215
|
+
|
216
|
+
# ========================================================================= #
|
217
|
+
# === exit_program (exit tag)
|
218
|
+
# ========================================================================= #
|
219
|
+
def exit_program # Use only this method to exit i-ftp.
|
220
|
+
e 'Bye from '+return_title+'! (@run_mode was '+simp(@run_mode.to_s)+')'
|
221
|
+
if @run_mode == :standalone # Not embedded.
|
222
|
+
@run_mode = :exit
|
223
|
+
disconnect
|
224
|
+
exit
|
225
|
+
else
|
226
|
+
@run_mode = :break
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
# ========================================================================= #
|
231
|
+
# === download_remote_file (download tag)
|
232
|
+
#
|
233
|
+
# This method will download a remote file. When we download a remote
|
234
|
+
# file, we will also set the remote base directory since Dec 2011.
|
235
|
+
# ========================================================================= #
|
236
|
+
def download_remote_file(
|
237
|
+
file = DEFAULT_REMOTE_FILE
|
238
|
+
)
|
239
|
+
file = DEFAULT_REMOTE_FILE if file.nil?
|
240
|
+
if file.include? '*'
|
241
|
+
file = ftp?.find_matches_for(file)
|
242
|
+
end
|
243
|
+
if file.is_a? Array
|
244
|
+
file.each {|the_file| download_remote_file(the_file) }
|
245
|
+
else
|
246
|
+
if file =~ /^\d+$/ # if is a number. DEBUG HERE THOUGH.
|
247
|
+
ftp?.update
|
248
|
+
file = ftp?.array_file_listing[file.to_i - 1][0]
|
249
|
+
end
|
250
|
+
set_remote_directory(file)
|
251
|
+
unless file == '*'
|
252
|
+
opne 'Trying to download `'+sfile(file)+'` now.'
|
253
|
+
# return_value = ftp?.download(file)
|
254
|
+
result = ftp?.download(file) # Delegate to the parent class.
|
255
|
+
if result
|
256
|
+
@array_downloaded_files << file
|
257
|
+
set_file(File.basename(file)) # setting new again.
|
258
|
+
if @open_in_default_editor # Works on @file now, as we did set it before.
|
259
|
+
open_this_file_in_editor(@file)
|
260
|
+
end
|
261
|
+
else
|
262
|
+
opne 'An exception occurred - you probably lack permissions to'
|
263
|
+
opne 'download that remote file.'
|
264
|
+
end
|
265
|
+
end
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
# ========================================================================= #
|
270
|
+
# === has_unwanted_file_suffix?
|
271
|
+
#
|
272
|
+
# The following method will return true or false.
|
273
|
+
#
|
274
|
+
# I needed it so that the editor does not open every file that was
|
275
|
+
# thrown at it.
|
276
|
+
# ========================================================================= #
|
277
|
+
def has_unwanted_file_suffix?(i)
|
278
|
+
return_value = false
|
279
|
+
case File.extname(i).delete('.')
|
280
|
+
when 'xz'
|
281
|
+
return_value = true
|
282
|
+
end
|
283
|
+
return return_value
|
284
|
+
end
|
285
|
+
|
286
|
+
# ========================================================================= #
|
287
|
+
# === debug_it
|
288
|
+
# ========================================================================= #
|
289
|
+
def debug_it # debug tag
|
290
|
+
ftp?.debug(true)
|
291
|
+
# pp ftp?.array_file_listing
|
292
|
+
end
|
293
|
+
|
294
|
+
# ========================================================================= #
|
295
|
+
# === set_local_directory
|
296
|
+
# ========================================================================= #
|
297
|
+
def set_local_directory(
|
298
|
+
i = Dir.pwd
|
299
|
+
)
|
300
|
+
i = i.to_s.dup
|
301
|
+
i << '/' unless i.end_with? '/'
|
302
|
+
i = FtpParadise.rds(i)
|
303
|
+
@local_directory = i
|
304
|
+
end
|
305
|
+
|
306
|
+
# ========================================================================= #
|
307
|
+
# === show_colours
|
308
|
+
# ========================================================================= #
|
309
|
+
def show_colours # Use this to show the colours.
|
310
|
+
pp Colours.colours?
|
311
|
+
end
|
312
|
+
|
313
|
+
# ========================================================================= #
|
314
|
+
# === debug?
|
315
|
+
# ========================================================================= #
|
316
|
+
def debug?
|
317
|
+
@debug
|
318
|
+
end
|
319
|
+
|
320
|
+
# ========================================================================= #
|
321
|
+
# === save_config
|
322
|
+
# ========================================================================= #
|
323
|
+
def save_config
|
324
|
+
@config.save
|
325
|
+
end
|
326
|
+
|
327
|
+
# ========================================================================= #
|
328
|
+
# === stat_remote_file (stat tag)
|
329
|
+
#
|
330
|
+
# This method can be called via '?33' for instance, or via 'stat 33'.
|
331
|
+
# ========================================================================= #
|
332
|
+
def stat_remote_file(i)
|
333
|
+
file = ftp?[i] # Obtain that file.
|
334
|
+
matches = ftp?.array_file_listing.select {|key,value| key == file }
|
335
|
+
matches.each { |entry|
|
336
|
+
e ' '+entry[0]+': '+sfancy(entry[2]+' KB')
|
337
|
+
}
|
338
|
+
end
|
339
|
+
|
340
|
+
# ========================================================================= #
|
341
|
+
# === show_local_entries
|
342
|
+
# ========================================================================= #
|
343
|
+
def show_local_entries
|
344
|
+
show_local_files(false)
|
345
|
+
end
|
346
|
+
|
347
|
+
# ========================================================================= #
|
348
|
+
# === return_local_files
|
349
|
+
#
|
350
|
+
# Return local files. Directories will not be included here.
|
351
|
+
# ========================================================================= #
|
352
|
+
def return_local_files
|
353
|
+
entries = Dir['*']
|
354
|
+
entries = Dir[Dir.pwd+'/*'] if show_full_names? # Overrule in this case.
|
355
|
+
entries.reject! {|entry| File.directory? entry }
|
356
|
+
return entries
|
357
|
+
end; alias file_listing return_local_files # === file_listing
|
358
|
+
|
359
|
+
# ========================================================================= #
|
360
|
+
# === return_local_entries
|
361
|
+
#
|
362
|
+
# Returns all local entries.
|
363
|
+
# ========================================================================= #
|
364
|
+
def return_local_entries
|
365
|
+
entries = Dir['*']
|
366
|
+
entries = Dir[Dir.pwd+'/*'] if show_full_names? # Overrule in this case.
|
367
|
+
return entries
|
368
|
+
end
|
369
|
+
|
370
|
+
# ========================================================================= #
|
371
|
+
# === coloured_remote_host?
|
372
|
+
# ========================================================================= #
|
373
|
+
def coloured_remote_host?
|
374
|
+
sfancy(remote_host?)
|
375
|
+
end
|
376
|
+
|
377
|
+
# ========================================================================= #
|
378
|
+
# === remote_host?
|
379
|
+
# ========================================================================= #
|
380
|
+
def remote_host?
|
381
|
+
ftp?.host?.to_s
|
382
|
+
end
|
383
|
+
|
384
|
+
# ========================================================================= #
|
385
|
+
# === enable_anonymous_login
|
386
|
+
#
|
387
|
+
# We use this method to enable anonymous logins.
|
388
|
+
# ========================================================================= #
|
389
|
+
def enable_anonymous_login
|
390
|
+
opne 'We will enable anonymous login now.'
|
391
|
+
set_password :anonymous
|
392
|
+
set_user_name 'anonymous'
|
393
|
+
end
|
394
|
+
|
395
|
+
# ========================================================================= #
|
396
|
+
# === create_directory
|
397
|
+
# ========================================================================= #
|
398
|
+
def create_directory(i, be_verbose = false)
|
399
|
+
be_verbose = true if be_verbose == :be_verbose
|
400
|
+
e 'Now creating local directory '+sdir(i)+'.' if be_verbose
|
401
|
+
FileUtils.mkdir_p(i)
|
402
|
+
end
|
403
|
+
|
404
|
+
# ========================================================================= #
|
405
|
+
# === report_file
|
406
|
+
#
|
407
|
+
# Here we simply report which file we would upload.
|
408
|
+
# ========================================================================= #
|
409
|
+
def report_file
|
410
|
+
if file?
|
411
|
+
e 'The file that we would upload is: '
|
412
|
+
e ' '+sfile(file?)
|
413
|
+
else
|
414
|
+
e 'No file was specified yet.'
|
415
|
+
end
|
416
|
+
end
|
417
|
+
|
418
|
+
# ========================================================================= #
|
419
|
+
# === move_local_file
|
420
|
+
# ========================================================================= #
|
421
|
+
def move_local_file(from, to)
|
422
|
+
e 'Next moving (local) file from '+sfile(from)+' to '+sfile(to)+'.'
|
423
|
+
if File.exist? from
|
424
|
+
FileUtils.mv(from, to)
|
425
|
+
else
|
426
|
+
e 'No (local) file called '+sfile(from)+' could be found.'
|
427
|
+
end
|
428
|
+
end
|
429
|
+
|
430
|
+
# ========================================================================= #
|
431
|
+
# === disconnect
|
432
|
+
#
|
433
|
+
# Disconnect the remote connection by invoking the quit() method on
|
434
|
+
# the FTP object.
|
435
|
+
# ========================================================================= #
|
436
|
+
def disconnect(be_verbose = true)
|
437
|
+
if ftp?.did_we_connect?
|
438
|
+
e 'Disconnected from `'+coloured_remote_host?+'`.' if be_verbose
|
439
|
+
end
|
440
|
+
ftp?.quit
|
441
|
+
exit
|
442
|
+
end
|
443
|
+
|
444
|
+
# ========================================================================= #
|
445
|
+
# === move_remote_file
|
446
|
+
#
|
447
|
+
# We expect an Array as input.
|
448
|
+
#
|
449
|
+
# To test this method, do:
|
450
|
+
# rmv DONE_Pr�fungsfragen_Hartig_Einheiten_2_3_5_9_10_11_12_15_16_21.pdf PDFs/
|
451
|
+
# mmv vimrc vim
|
452
|
+
# ========================================================================= #
|
453
|
+
def move_remote_file(i)
|
454
|
+
from = i[0]
|
455
|
+
to = i[1]
|
456
|
+
if is_directory?(to)
|
457
|
+
to << '/' unless to.end_with? '/'
|
458
|
+
to << File.basename(from)
|
459
|
+
end
|
460
|
+
e 'Next moving from '+sfancy(from)+' to '+sfancy(to)+'.'
|
461
|
+
ftp?.move_file(from, to)
|
462
|
+
end
|
463
|
+
|
464
|
+
# ========================================================================= #
|
465
|
+
# === register_sigint
|
466
|
+
# ========================================================================= #
|
467
|
+
def register_sigint
|
468
|
+
Signal.trap('SIGINT') {
|
469
|
+
e 'Please use "q" to quit.'
|
470
|
+
}
|
471
|
+
end
|
472
|
+
|
473
|
+
# ========================================================================= #
|
474
|
+
# === disable
|
475
|
+
# ========================================================================= #
|
476
|
+
def disable(i = nil)
|
477
|
+
i = i.to_s.to_sym
|
478
|
+
case i
|
479
|
+
when :base_directory, :full_names
|
480
|
+
do_not_show_full_names
|
481
|
+
when :debug
|
482
|
+
@config.debug = false
|
483
|
+
ftp?.disable_debug
|
484
|
+
save_config
|
485
|
+
end
|
486
|
+
e 'Disabling '+sfancy(i.to_s)+' now.' unless i.to_s.empty?
|
487
|
+
end
|
488
|
+
|
489
|
+
# ========================================================================= #
|
490
|
+
# === toggle_show_full_names
|
491
|
+
# ========================================================================= #
|
492
|
+
def toggle_show_full_names
|
493
|
+
@config.show_full_names = ! @config.show_full_names
|
494
|
+
end
|
495
|
+
|
496
|
+
# ========================================================================= #
|
497
|
+
# === do_not_show_full_names
|
498
|
+
# ========================================================================= #
|
499
|
+
def do_not_show_full_names
|
500
|
+
ftp?.show_full_names = false
|
501
|
+
@config.show_full_names = false # Sync.
|
502
|
+
end
|
503
|
+
|
504
|
+
# ========================================================================= #
|
505
|
+
# === do_show_full_names
|
506
|
+
# ========================================================================= #
|
507
|
+
def do_show_full_names
|
508
|
+
ftp?.show_full_names = true
|
509
|
+
@config.show_full_names = true # Sync.
|
510
|
+
end
|
511
|
+
|
512
|
+
# ========================================================================= #
|
513
|
+
# === will_we_show_full_names
|
514
|
+
# ========================================================================= #
|
515
|
+
def will_we_show_full_names
|
516
|
+
e 'Will we now show full names? '+
|
517
|
+
verbose_truth(show_full_names?)
|
518
|
+
end
|
519
|
+
|
520
|
+
# ========================================================================= #
|
521
|
+
# === report_last_response
|
522
|
+
# ========================================================================= #
|
523
|
+
def report_last_response
|
524
|
+
e 'The last response was: '+simp(ftp?.ftp.last_response.to_s)
|
525
|
+
end
|
526
|
+
|
527
|
+
# ========================================================================= #
|
528
|
+
# === report_last_response_code
|
529
|
+
# ========================================================================= #
|
530
|
+
def report_last_response_code
|
531
|
+
e 'The last response code was: '+simp(ftp?.ftp.last_response_code.to_s)
|
532
|
+
end
|
533
|
+
|
534
|
+
# ========================================================================= #
|
535
|
+
# === set_commandline_arguments
|
536
|
+
# ========================================================================= #
|
537
|
+
def set_commandline_arguments(i)
|
538
|
+
@commandline_arguments = i
|
539
|
+
end
|
540
|
+
|
541
|
+
# ========================================================================= #
|
542
|
+
# === check_commandline_arguments (commandline tag)
|
543
|
+
#
|
544
|
+
# This is called from within method enter_loop().
|
545
|
+
# ========================================================================= #
|
546
|
+
def check_commandline_arguments(
|
547
|
+
i = @commandline_arguments
|
548
|
+
)
|
549
|
+
if i.is_a?(String) and i.include?(',') # Here we assume a chained-instruction.
|
550
|
+
i = i.split(',')
|
551
|
+
end
|
552
|
+
i = [i].flatten.compact
|
553
|
+
i.each {|entry|
|
554
|
+
case entry
|
555
|
+
when '',nil # Do nothing in this case.
|
556
|
+
when '--disable-colours','--disable-colors','nocolours','nocol',
|
557
|
+
/^-?-?nocol$/
|
558
|
+
e 'Now disabling colours.'
|
559
|
+
FtpParadise.disable_colours
|
560
|
+
when *ARRAY_HELP_OPTIONS
|
561
|
+
show_commandline_help
|
562
|
+
exit
|
563
|
+
when 'BINARY'
|
564
|
+
set_binary :be_verbose
|
565
|
+
else
|
566
|
+
entry = entry.to_s
|
567
|
+
if File.exist?(entry)
|
568
|
+
set_file(entry)
|
569
|
+
@commandline_arguments.reject! {|line|
|
570
|
+
line.include? entry
|
571
|
+
}
|
572
|
+
end
|
573
|
+
end
|
574
|
+
}
|
575
|
+
end
|
576
|
+
|
577
|
+
# ========================================================================= #
|
578
|
+
# === show_commandline_help
|
579
|
+
#
|
580
|
+
# This method is different from "normal" help. The "normal" help will
|
581
|
+
# be displayed when we are already running in interactive mode. The
|
582
|
+
# commandline help however had will be run when we are invoking it
|
583
|
+
# from the commandline.
|
584
|
+
# ========================================================================= #
|
585
|
+
def show_commandline_help
|
586
|
+
opne 'These options are currently supported:'
|
587
|
+
opn(use_colours?); Colours.ecomment ' --disable-colours # Run without colours.'
|
588
|
+
end
|
589
|
+
|
590
|
+
# ========================================================================= #
|
591
|
+
# === show_welcome_message
|
592
|
+
#
|
593
|
+
# The initial startup message to welcome the user.
|
594
|
+
# ========================================================================= #
|
595
|
+
def show_welcome_message
|
596
|
+
e 'Welcome to the '+return_title+' shell.'
|
597
|
+
e 'Input '+sfancy('"help"')+' to show the help-section.'
|
598
|
+
e 'Please input commands next:'
|
599
|
+
end
|
600
|
+
|
601
|
+
# ========================================================================= #
|
602
|
+
# === show_ftp_server_welcome
|
603
|
+
#
|
604
|
+
# Simply show the FTP server's welcome message.
|
605
|
+
# ========================================================================= #
|
606
|
+
def show_ftp_server_welcome
|
607
|
+
e ftp?.welcome
|
608
|
+
end
|
609
|
+
|
610
|
+
# ========================================================================= #
|
611
|
+
# === return_title
|
612
|
+
# ========================================================================= #
|
613
|
+
def return_title
|
614
|
+
sfancy(TITLE)
|
615
|
+
end
|
616
|
+
|
617
|
+
# ========================================================================= #
|
618
|
+
# === try_to_append_this_to_the_history
|
619
|
+
#
|
620
|
+
# Right now only 'last' is a forbidden entry.
|
621
|
+
# ========================================================================= #
|
622
|
+
def try_to_append_this_to_the_history(i)
|
623
|
+
unless i.empty?
|
624
|
+
@history << i unless ARRAY_FORBIDDEN_HISTORY_COMMANDS.include? i
|
625
|
+
end
|
626
|
+
end
|
627
|
+
|
628
|
+
# ========================================================================= #
|
629
|
+
# === load_config
|
630
|
+
#
|
631
|
+
# This method will load the configuration for this class.
|
632
|
+
# ========================================================================= #
|
633
|
+
def load_config
|
634
|
+
@config = ::Roebe::Configuration::Configuration.new(FtpParadise.yaml_directory?)
|
635
|
+
@open_in_default_editor = OPEN_IN_DEFAULT_EDITOR
|
636
|
+
if @config.has_entry? 'open_in_default_editor'
|
637
|
+
@open_in_default_editor = @config.open_in_default_editor
|
638
|
+
end
|
639
|
+
if @config.respond_to? :debug
|
640
|
+
@debug = @config.debug # Obtain (or rather, overrule) the @debug variable.
|
641
|
+
end
|
642
|
+
end
|
643
|
+
|
644
|
+
# ========================================================================= #
|
645
|
+
# === report_port
|
646
|
+
# ========================================================================= #
|
647
|
+
def report_port
|
648
|
+
e 'The port in use is: '+sfancy(ftp?.port)
|
649
|
+
end
|
650
|
+
|
651
|
+
# ========================================================================= #
|
652
|
+
# === get_env_of
|
653
|
+
# ========================================================================= #
|
654
|
+
def get_env_of(i)
|
655
|
+
ConvertGlobalEnv.convert(i, ConvertGlobalEnv.report_errors?)
|
656
|
+
end
|
657
|
+
|
658
|
+
# ========================================================================= #
|
659
|
+
# === file?
|
660
|
+
#
|
661
|
+
# This may always be a String.
|
662
|
+
# ========================================================================= #
|
663
|
+
def file?
|
664
|
+
@file.to_s
|
665
|
+
end
|
666
|
+
|
667
|
+
# ========================================================================= #
|
668
|
+
# === consider_reporting_file
|
669
|
+
# ========================================================================= #
|
670
|
+
def consider_reporting_file
|
671
|
+
if file?.empty?
|
672
|
+
e 'No file has been assigned yet.'
|
673
|
+
e 'You can set a specific file via '+simportant('"set_file"')+'.'
|
674
|
+
else
|
675
|
+
report_file
|
676
|
+
end
|
677
|
+
end
|
678
|
+
|
679
|
+
# ========================================================================= #
|
680
|
+
# === toggle (toggle tag)
|
681
|
+
#
|
682
|
+
# Simply toggle the value for whether we @config.show_full_names or not.
|
683
|
+
# ========================================================================= #
|
684
|
+
def toggle(
|
685
|
+
i = :names
|
686
|
+
)
|
687
|
+
i = i.to_s
|
688
|
+
i = 'mode' if i.empty? # Safeguard.
|
689
|
+
case i
|
690
|
+
# ======================================================================= #
|
691
|
+
# === mode
|
692
|
+
# ======================================================================= #
|
693
|
+
when 'mode'
|
694
|
+
if @mode == :binary
|
695
|
+
use_ascii_mode
|
696
|
+
else
|
697
|
+
use_binary_mode
|
698
|
+
end
|
699
|
+
when 'names','name'
|
700
|
+
toggle_show_full_names
|
701
|
+
will_we_show_full_names
|
702
|
+
end
|
703
|
+
e 'We will now toggle '+sfancy(i)+' to '+simp(@mode.to_s)+'.'
|
704
|
+
end; alias show_full_names toggle # === show_full_names
|
705
|
+
|
706
|
+
# ========================================================================= #
|
707
|
+
# === show_user_and_password
|
708
|
+
# ========================================================================= #
|
709
|
+
def show_user_and_password
|
710
|
+
ftp?.show_user_and_password
|
711
|
+
end
|
712
|
+
|
713
|
+
# ========================================================================= #
|
714
|
+
# === show_host_user_name_port_and_password
|
715
|
+
# ========================================================================= #
|
716
|
+
def show_host_user_name_port_and_password
|
717
|
+
ftp?.show_host_user_name_port_and_password
|
718
|
+
end
|
719
|
+
|
720
|
+
# ========================================================================= #
|
721
|
+
# === show_local_files
|
722
|
+
#
|
723
|
+
# This method shows the local file listing. That is, all the entries in
|
724
|
+
# the given directory.
|
725
|
+
# ========================================================================= #
|
726
|
+
def show_local_files(show_only_directories = true)
|
727
|
+
_ = Dir.pwd
|
728
|
+
if Dir.entries(_).size == 2 # Dir.empty?, we assume that we have '.' and '..' only
|
729
|
+
e 'The directory `'+sdir(_)+'` is empty.'
|
730
|
+
else
|
731
|
+
e 'Showing local files now from `'+sdir(_)+'`:'
|
732
|
+
e ('=' * 55)+' '+FtpParadise.yellow('LOCAL FILES')+' '+('=' * 12)
|
733
|
+
entries = return_local_entries
|
734
|
+
entries.reject! {|x| ! File.directory?(x) } if show_only_directories
|
735
|
+
entries.sort.each_with_index { |item, index|
|
736
|
+
case File.ftype(item)
|
737
|
+
when 'directory'
|
738
|
+
item = sdir(item+'/')
|
739
|
+
when 'file'
|
740
|
+
item = sfile(item)
|
741
|
+
end
|
742
|
+
e '('+('%2s' % (index+1).to_s)+') '+FtpParadise.rds(item)
|
743
|
+
}
|
744
|
+
cliner
|
745
|
+
end
|
746
|
+
end
|
747
|
+
|
748
|
+
# ========================================================================= #
|
749
|
+
# === convert_number_to_file
|
750
|
+
#
|
751
|
+
# Use this to convert a number.
|
752
|
+
# convert_number_to_file(i) if i =~ /^\d+$/
|
753
|
+
# ========================================================================= #
|
754
|
+
def convert_number_to_file(number)
|
755
|
+
number = number.to_s.chomp
|
756
|
+
if number =~ /^\d+$/ # if is a number
|
757
|
+
ftp?.update_file_listing
|
758
|
+
number = ftp?.array_file_listing[number.to_i - 1][0]
|
759
|
+
end
|
760
|
+
return number
|
761
|
+
end
|
762
|
+
|
763
|
+
# ========================================================================= #
|
764
|
+
# === is_dir?
|
765
|
+
#
|
766
|
+
# Return true or false, depending on whether the input is a directory
|
767
|
+
# or whether it is not.
|
768
|
+
# ========================================================================= #
|
769
|
+
def is_dir?(i)
|
770
|
+
ftp?.is_directory?(i)
|
771
|
+
end; alias is_directory? is_dir? # === is_directory?
|
772
|
+
|
773
|
+
# ========================================================================= #
|
774
|
+
# === is_file?
|
775
|
+
# ========================================================================= #
|
776
|
+
def is_file?(i)
|
777
|
+
ftp?.is_file?(i)
|
778
|
+
end
|
779
|
+
|
780
|
+
# ========================================================================= #
|
781
|
+
# === this_remote_entry_exists?
|
782
|
+
# ========================================================================= #
|
783
|
+
def this_remote_entry_exists?(i)
|
784
|
+
does_it_exist = false
|
785
|
+
does_it_exist = true if is_dir? i # This will also check whether it exists.
|
786
|
+
does_it_exist = true if is_file? i
|
787
|
+
return does_it_exist
|
788
|
+
end
|
789
|
+
|
790
|
+
# ========================================================================= #
|
791
|
+
# === show_date_sorted_entries
|
792
|
+
#
|
793
|
+
# This method will show the sorted entries of the given remote directory
|
794
|
+
# at hand.
|
795
|
+
# ========================================================================= #
|
796
|
+
def show_date_sorted_entries
|
797
|
+
dataset = ftp?.array_file_listing?
|
798
|
+
reverse_sort_dateset = dataset.sort_by {|_a,_b_,_c, timestamp|
|
799
|
+
timestamp
|
800
|
+
}.reverse
|
801
|
+
ftp?.show_remote_listing(reverse_sort_dateset)
|
802
|
+
end
|
803
|
+
|
804
|
+
# ========================================================================= #
|
805
|
+
# === set_name
|
806
|
+
# ========================================================================= #
|
807
|
+
def set_name(i)
|
808
|
+
i = i.to_s
|
809
|
+
e 'Setting user-name to `'+sfancy(i)+'` now.'
|
810
|
+
ftp?.set_user_name(i)
|
811
|
+
end; alias set_user_name set_name # === set_user_name
|
812
|
+
|
813
|
+
# ========================================================================= #
|
814
|
+
# === show_full_names?
|
815
|
+
# ========================================================================= #
|
816
|
+
def show_full_names?
|
817
|
+
@config.show_full_names
|
818
|
+
end
|
819
|
+
|
820
|
+
# ========================================================================= #
|
821
|
+
# === create_remote_directory
|
822
|
+
# ========================================================================= #
|
823
|
+
def create_remote_directory(i)
|
824
|
+
ftp?.mkdir(i)
|
825
|
+
end
|
826
|
+
|
827
|
+
# ========================================================================= #
|
828
|
+
# === opne
|
829
|
+
# ========================================================================= #
|
830
|
+
def opne(message)
|
831
|
+
opnn; e message
|
832
|
+
end
|
833
|
+
|
834
|
+
# ========================================================================= #
|
835
|
+
# === opnn
|
836
|
+
# ========================================================================= #
|
837
|
+
def opnn(i = {namespace: NAMESPACE, use_colours: use_colours?})
|
838
|
+
Opn.opn(i)
|
839
|
+
end
|
840
|
+
|
841
|
+
# ========================================================================= #
|
842
|
+
# === set_login
|
843
|
+
# ========================================================================= #
|
844
|
+
def set_login(i)
|
845
|
+
ftp?.set_login_name(i)
|
846
|
+
end
|
847
|
+
|
848
|
+
# ========================================================================= #
|
849
|
+
# === user_input?
|
850
|
+
# ========================================================================= #
|
851
|
+
def user_input?
|
852
|
+
@user_input
|
853
|
+
end
|
854
|
+
|
855
|
+
# ========================================================================= #
|
856
|
+
# === report_where_we_are_connected_to
|
857
|
+
# ========================================================================= #
|
858
|
+
def report_where_we_are_connected_to
|
859
|
+
if are_we_connected?
|
860
|
+
e 'We are connected to: '+simportant(ftp?.remote?)
|
861
|
+
else
|
862
|
+
e 'We are not connected. Invoke "do_connect" to connect to a FTP host.'
|
863
|
+
end
|
864
|
+
end
|
865
|
+
|
866
|
+
# ========================================================================= #
|
867
|
+
# === return_remote_files
|
868
|
+
#
|
869
|
+
# We call into FtpParadise::Connection here.
|
870
|
+
# ========================================================================= #
|
871
|
+
def return_remote_files(mode = nil)
|
872
|
+
ftp?.show_full_names if show_full_names? # Display the full path here.
|
873
|
+
ftp?.return_remote_files
|
874
|
+
end
|
875
|
+
|
876
|
+
# ========================================================================= #
|
877
|
+
# === are_we_connected?
|
878
|
+
# ========================================================================= #
|
879
|
+
def are_we_connected?
|
880
|
+
@are_we_connected
|
881
|
+
end; alias is_connected? are_we_connected? # === is_connected?
|
882
|
+
|
883
|
+
# ========================================================================= #
|
884
|
+
# === automatically_connect_on_startup_of_the_interactive_ftp_shell?
|
885
|
+
# ========================================================================= #
|
886
|
+
def automatically_connect_on_startup_of_the_interactive_ftp_shell?
|
887
|
+
_ = FILE_AUTOMATICALLY_CONNECT_ON_STARTUP_OF_THE_INTERACTIVE_FTP_SHELL
|
888
|
+
if File.exist? _
|
889
|
+
YAML.load_file(_)
|
890
|
+
else
|
891
|
+
false # In this case we default to false.
|
892
|
+
end
|
893
|
+
end
|
894
|
+
|
895
|
+
# ========================================================================= #
|
896
|
+
# === startup_actions
|
897
|
+
#
|
898
|
+
# This method can be used to designate startup actions - which are actions
|
899
|
+
# that are run when the interactive ftp-shell is first started.
|
900
|
+
#
|
901
|
+
# Presently (Sep 2018) we will only consider two startup actions:
|
902
|
+
#
|
903
|
+
# (1) Consider making use of the Readline Module
|
904
|
+
# (2) auto-connecting on startup if a certain yaml-configuration file
|
905
|
+
# has an entry set to true, and if we are on roebe.
|
906
|
+
#
|
907
|
+
# ========================================================================= #
|
908
|
+
def startup_actions
|
909
|
+
# ======================================================================= #
|
910
|
+
# We will next try to make use of the Readline-module, if it is available:
|
911
|
+
# ======================================================================= #
|
912
|
+
try_to_use_readline
|
913
|
+
if are_we_on_roebe? and automatically_connect_on_startup_of_the_interactive_ftp_shell?
|
914
|
+
# ===================================================================== #
|
915
|
+
# The next is for my home system mostly; not sure if it is worth
|
916
|
+
# to make it more general for other people too.
|
917
|
+
# ===================================================================== #
|
918
|
+
do_login_to_shevy_and_consider_showing_the_remote_files
|
919
|
+
end
|
920
|
+
end
|
921
|
+
|
922
|
+
# ========================================================================= #
|
923
|
+
# === set_active
|
924
|
+
# ========================================================================= #
|
925
|
+
def set_active
|
926
|
+
ftp?.set_active
|
927
|
+
end
|
928
|
+
|
929
|
+
# ========================================================================= #
|
930
|
+
# === datafile?
|
931
|
+
# ========================================================================= #
|
932
|
+
def datafile?
|
933
|
+
'$MY_FTP/YAML/roebe_ftp.yml'
|
934
|
+
end
|
935
|
+
|
936
|
+
# ========================================================================= #
|
937
|
+
# === display_prompt
|
938
|
+
# ========================================================================= #
|
939
|
+
def display_prompt
|
940
|
+
print PROMPT_TO_USE
|
941
|
+
end
|
942
|
+
|
943
|
+
# ========================================================================= #
|
944
|
+
# === download?
|
945
|
+
# ========================================================================= #
|
946
|
+
def download?
|
947
|
+
e 'The remote file we would download is: '
|
948
|
+
e
|
949
|
+
e " #{sfile(DEFAULT_REMOTE_FILE)}"
|
950
|
+
e
|
951
|
+
end
|
952
|
+
|
953
|
+
# ========================================================================= #
|
954
|
+
# === do_login_to_shevy_and_consider_showing_the_remote_files
|
955
|
+
# ========================================================================= #
|
956
|
+
def do_login_to_shevy_and_consider_showing_the_remote_files
|
957
|
+
do_login(:shevy)
|
958
|
+
if SHOW_REMOTE_FILES_UPON_SUCCESSFUL_LOGIN
|
959
|
+
show_remote_files :also_show_filesize # Also display this since as of March 2015.
|
960
|
+
end
|
961
|
+
end
|
962
|
+
|
963
|
+
# ========================================================================= #
|
964
|
+
# === do_login
|
965
|
+
#
|
966
|
+
# If the first argument is :dont_login_yet, which is the default,
|
967
|
+
# we will not yet connect.
|
968
|
+
# ========================================================================= #
|
969
|
+
def do_login(
|
970
|
+
i = :dont_login_yet
|
971
|
+
)
|
972
|
+
i = nil if i == :dont_login_yet
|
973
|
+
if i
|
974
|
+
# ===================================================================== #
|
975
|
+
# Next, feed this information to the ftp? object.
|
976
|
+
# ===================================================================== #
|
977
|
+
ftp?.set_data(i)
|
978
|
+
ftp?.do_login # bl $RUBY_FTP/ftp_library.rb
|
979
|
+
@are_we_connected = true
|
980
|
+
end
|
981
|
+
end
|
982
|
+
|
983
|
+
end
|
984
|
+
|
985
|
+
# =========================================================================== #
|
986
|
+
# === FtpParadise.interactive
|
987
|
+
#
|
988
|
+
# Convenience method to instantiate a new class Interactive instance.
|
989
|
+
# =========================================================================== #
|
990
|
+
def self.interactive(i = ARGV)
|
991
|
+
FtpParadise::InteractiveFtp.new(i)
|
992
|
+
end
|
993
|
+
|
994
|
+
end
|
995
|
+
|
996
|
+
if __FILE__ == $PROGRAM_NAME
|
997
|
+
FtpParadise.interactive(ARGV)
|
998
|
+
end # iftp
|