ftp_paradise 1.3.8
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of ftp_paradise might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/README.md +309 -0
- data/bin/create_remote_directory +9 -0
- data/bin/ftp_get +17 -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 +292 -0
- data/doc/TODO_FOR_FTP_PARADISE_PROJECT.md +79 -0
- data/ftp_paradise.gemspec +114 -0
- data/lib/ftp_paradise.rb +5 -0
- data/lib/ftp_paradise/base/cliner.rb +21 -0
- data/lib/ftp_paradise/base/colours.rb +83 -0
- data/lib/ftp_paradise/base/prototype.rb +169 -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 +74 -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 +148 -0
- data/lib/ftp_paradise/connection/debug.rb +80 -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 +172 -0
- data/lib/ftp_paradise/connection/ftp_object.rb +21 -0
- data/lib/ftp_paradise/connection/initialize.rb +86 -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 +472 -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 +163 -0
- data/lib/ftp_paradise/connection/remove.rb +143 -0
- data/lib/ftp_paradise/connection/reset.rb +75 -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 +162 -0
- data/lib/ftp_paradise/connection/upload.rb +253 -0
- data/lib/ftp_paradise/connection/use_default_dataset.rb +41 -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 +27 -0
- data/lib/ftp_paradise/constants/roebe_ftp_constants.rb +219 -0
- data/lib/ftp_paradise/entry/entry.rb +293 -0
- data/lib/ftp_paradise/gui/gtk/constants.rb +58 -0
- data/lib/ftp_paradise/gui/gtk/ftp_bindings.rb +1149 -0
- data/lib/ftp_paradise/interactive_ftp/constants.rb +103 -0
- data/lib/ftp_paradise/interactive_ftp/directory_handling.rb +215 -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 +995 -0
- data/lib/ftp_paradise/interactive_ftp/main_loop.rb +50 -0
- data/lib/ftp_paradise/interactive_ftp/menu.rb +788 -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 +115 -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 +62 -0
- data/lib/ftp_paradise/requires/common_basic_requires.rb +13 -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 +29 -0
- data/lib/ftp_paradise/toplevel_methods/clear_user_dataset.rb +28 -0
- data/lib/ftp_paradise/toplevel_methods/connect.rb +49 -0
- data/lib/ftp_paradise/toplevel_methods/create_file.rb +18 -0
- data/lib/ftp_paradise/toplevel_methods/data.rb +31 -0
- data/lib/ftp_paradise/toplevel_methods/delete.rb +23 -0
- data/lib/ftp_paradise/toplevel_methods/determine_user_dataset_from_this_hash.rb +37 -0
- data/lib/ftp_paradise/toplevel_methods/e.rb +16 -0
- data/lib/ftp_paradise/toplevel_methods/ftp_object.rb +270 -0
- data/lib/ftp_paradise/toplevel_methods/get_files.rb +24 -0
- data/lib/ftp_paradise/toplevel_methods/is_directory.rb +33 -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/opn.rb +24 -0
- data/lib/ftp_paradise/toplevel_methods/password.rb +48 -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.rb +29 -0
- data/lib/ftp_paradise/toplevel_methods/upload_this_binary_file.rb +58 -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 +35 -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 +315 -0
@@ -0,0 +1,208 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'ftp_paradise/interactive_ftp/misc.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
require 'ftp_paradise/interactive_ftp/directory_handling.rb'
|
8
|
+
|
9
|
+
module FtpParadise
|
10
|
+
|
11
|
+
class InteractiveFtp < FtpParadise::Base
|
12
|
+
|
13
|
+
require 'ftp_paradise/toplevel_methods/determine_user_dataset_from_this_hash.rb'
|
14
|
+
|
15
|
+
# ========================================================================= #
|
16
|
+
# === set_editor
|
17
|
+
# ========================================================================= #
|
18
|
+
def set_editor(
|
19
|
+
i, be_verbose = true
|
20
|
+
)
|
21
|
+
i = i.first if i.is_a? Array
|
22
|
+
if be_verbose
|
23
|
+
opnn; e "Now using the editor called `#{sfancy(i)}`."
|
24
|
+
end
|
25
|
+
@use_this_editor = i
|
26
|
+
end
|
27
|
+
|
28
|
+
# ========================================================================= #
|
29
|
+
# === report_which_editor_is_in_use
|
30
|
+
# ========================================================================= #
|
31
|
+
def report_which_editor_is_in_use
|
32
|
+
opnn; e "The editor in use is `#{sfancy(@use_this_editor)}`."
|
33
|
+
end
|
34
|
+
|
35
|
+
# ========================================================================= #
|
36
|
+
# === open_this_file_in_editor (edit tag, editor tag, open tag)
|
37
|
+
#
|
38
|
+
# If you pass as first argument to this method the string 'ALL', we
|
39
|
+
# will try to open the (local) project files in your editor.
|
40
|
+
#
|
41
|
+
# To test this, do:
|
42
|
+
#
|
43
|
+
# open ALL
|
44
|
+
# open YAML
|
45
|
+
#
|
46
|
+
# ========================================================================= #
|
47
|
+
def open_this_file_in_editor(
|
48
|
+
this_file = @file
|
49
|
+
)
|
50
|
+
this_file = ARRAY_PROJECT_FILES if this_file.nil?
|
51
|
+
if this_file.is_a? Array
|
52
|
+
this_file.each {|entry| open_this_file_in_editor(entry) }
|
53
|
+
else
|
54
|
+
this_file = this_file.to_s
|
55
|
+
if this_file == 'TODO'
|
56
|
+
this_file = ARRAY_PROJECT_FILES.select {|entry| entry.include? 'TODO' }[0]
|
57
|
+
end
|
58
|
+
if this_file.to_s =~ /^\d+$/ # If only numbers were given.
|
59
|
+
this_file = Dir['*'].sort[this_file.to_i - 1]
|
60
|
+
end
|
61
|
+
this_file = NAME_OF_THIS_FILE if this_file.empty?
|
62
|
+
if this_file == 'ALL' and ! File.exist?('ALL')
|
63
|
+
open_this_file_in_editor(ARRAY_PROJECT_FILES)
|
64
|
+
elsif this_file == 'YAML' and ! File.exist?('YAML')
|
65
|
+
open_this_file_in_editor(YAML_FILE)
|
66
|
+
else
|
67
|
+
_ = @use_this_editor+" #{this_file}"
|
68
|
+
if File.exist?(this_file) && File.file?(this_file)
|
69
|
+
unless has_unwanted_file_suffix?(this_file)
|
70
|
+
e 'Loading '+sfile(this_file)+' in editor '+
|
71
|
+
'now as '+simp('USE_THIS_EDITOR')+' was set '+
|
72
|
+
'to true:'
|
73
|
+
e ' '+_+' &'
|
74
|
+
`#{_}`
|
75
|
+
end
|
76
|
+
set_file(this_file) # Since 24.12.2011 we also assign it.
|
77
|
+
else
|
78
|
+
e swarn('But the file `')+sfile(this_file)+
|
79
|
+
swarn('` does not exist.')
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end; alias open_in_editor open_this_file_in_editor # === open_in_editor
|
84
|
+
|
85
|
+
# ========================================================================= #
|
86
|
+
# === determine_user_dataset_from_this_hash
|
87
|
+
#
|
88
|
+
# This method can set relevant entries from an input Hash.
|
89
|
+
# ========================================================================= #
|
90
|
+
def determine_user_dataset_from_this_hash(
|
91
|
+
i,
|
92
|
+
optional_use_this_entry = :default
|
93
|
+
)
|
94
|
+
if optional_use_this_entry
|
95
|
+
case optional_use_this_entry
|
96
|
+
# ===================================================================== #
|
97
|
+
# === :default
|
98
|
+
# ===================================================================== #
|
99
|
+
when :default
|
100
|
+
optional_use_this_entry = :bplaced
|
101
|
+
end
|
102
|
+
end
|
103
|
+
FtpParadise.determine_user_dataset_from_this_hash(i)
|
104
|
+
end
|
105
|
+
|
106
|
+
# ========================================================================= #
|
107
|
+
# === set_password
|
108
|
+
# ========================================================================= #
|
109
|
+
def set_password(
|
110
|
+
i, be_verbose = be_verbose?
|
111
|
+
)
|
112
|
+
i = i.to_s
|
113
|
+
if be_verbose
|
114
|
+
e "Setting password to #{sfancy(i)} now."
|
115
|
+
end
|
116
|
+
FtpParadise.set_password(i)
|
117
|
+
end
|
118
|
+
|
119
|
+
# ========================================================================= #
|
120
|
+
# === pass_commandline_arguments_into_the_menu
|
121
|
+
# ========================================================================= #
|
122
|
+
def pass_commandline_arguments_into_the_menu
|
123
|
+
menu(@commandline_arguments)
|
124
|
+
end
|
125
|
+
|
126
|
+
# ========================================================================= #
|
127
|
+
# === set_port
|
128
|
+
#
|
129
|
+
# Use this method to set the port.
|
130
|
+
# ========================================================================= #
|
131
|
+
def set_port(
|
132
|
+
i = 21, be_verbose = false
|
133
|
+
)
|
134
|
+
if be_verbose
|
135
|
+
e "Setting port to #{sfancy(i)} now."
|
136
|
+
end
|
137
|
+
ftp?.set_port(i)
|
138
|
+
end
|
139
|
+
|
140
|
+
# ========================================================================= #
|
141
|
+
# === remote_url?
|
142
|
+
# ========================================================================= #
|
143
|
+
def remote_url?
|
144
|
+
FtpParadise.remote_url?
|
145
|
+
end; alias remote_host? remote_url? # === remote_host?
|
146
|
+
|
147
|
+
# ========================================================================= #
|
148
|
+
# === password?
|
149
|
+
# ========================================================================= #
|
150
|
+
def password?
|
151
|
+
FtpParadise.password?
|
152
|
+
end
|
153
|
+
|
154
|
+
# ========================================================================= #
|
155
|
+
# === remote_remove_file
|
156
|
+
# ========================================================================= #
|
157
|
+
def remote_remove_file(
|
158
|
+
i = @first_argument
|
159
|
+
)
|
160
|
+
if i.is_a? Array
|
161
|
+
i.each {|entry| remote_remove_file(entry) }
|
162
|
+
else
|
163
|
+
e "Trying to remove `#{sfile(i)}` next:"
|
164
|
+
@ftp.delete(i)
|
165
|
+
end
|
166
|
+
end; alias remote_remove_files remote_remove_file # === remote_remove_files
|
167
|
+
|
168
|
+
# ========================================================================= #
|
169
|
+
# === display_file
|
170
|
+
#
|
171
|
+
# Use this method to display a file in question.
|
172
|
+
# ========================================================================= #
|
173
|
+
def display_file(i)
|
174
|
+
if File.exist? i
|
175
|
+
_ = File.readlines(i).join
|
176
|
+
e _
|
177
|
+
else
|
178
|
+
ewarn "File #{sfile(i)} does not exist."
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
# ========================================================================= #
|
183
|
+
# === report_version
|
184
|
+
# ========================================================================= #
|
185
|
+
def report_version
|
186
|
+
e sfancy(FtpParadise::VERSION)
|
187
|
+
end
|
188
|
+
|
189
|
+
# ========================================================================= #
|
190
|
+
# === all_arguments?
|
191
|
+
#
|
192
|
+
# The alias a? may be an easier wrapper over @all_arguments.
|
193
|
+
# ========================================================================= #
|
194
|
+
def all_arguments?
|
195
|
+
@all_arguments
|
196
|
+
end; alias a? all_arguments? # === a?
|
197
|
+
|
198
|
+
# ========================================================================= #
|
199
|
+
# === try_to_chmod_this_remote_file
|
200
|
+
# ========================================================================= #
|
201
|
+
def try_to_chmod_this_remote_file(
|
202
|
+
filename, chmod_value_to_use = '0777'
|
203
|
+
)
|
204
|
+
e "Trying to chmod the remote file #{filename} next."
|
205
|
+
ftp?.sendcmd("SITE CHMOD #{chmod_value_to_use} #{filename}")
|
206
|
+
end
|
207
|
+
|
208
|
+
end; end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'ftp_paradise/interactive_ftp/mode.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module FtpParadise
|
8
|
+
|
9
|
+
class InteractiveFtp < FtpParadise::Base # === FtpParadise::InteractiveFtp
|
10
|
+
|
11
|
+
# ========================================================================= #
|
12
|
+
# === use_binary_mode
|
13
|
+
#
|
14
|
+
# This enables use the binary mode.
|
15
|
+
# ========================================================================= #
|
16
|
+
def use_binary_mode(
|
17
|
+
be_verbose = false
|
18
|
+
)
|
19
|
+
case be_verbose
|
20
|
+
when :be_quiet
|
21
|
+
be_verbose = false
|
22
|
+
when :be_verbose
|
23
|
+
be_verbose = true
|
24
|
+
end
|
25
|
+
e 'Using binary mode now.' if be_verbose
|
26
|
+
set_mode :binary
|
27
|
+
end; alias set_binary use_binary_mode # === set_binary
|
28
|
+
|
29
|
+
# ========================================================================= #
|
30
|
+
# === set_mode
|
31
|
+
#
|
32
|
+
# Set the mode here. We default to :ascii mode.
|
33
|
+
#
|
34
|
+
# There are only two valid modes:
|
35
|
+
#
|
36
|
+
# :ascii
|
37
|
+
# :binary
|
38
|
+
#
|
39
|
+
# ========================================================================= #
|
40
|
+
def set_mode(
|
41
|
+
i = :ascii
|
42
|
+
)
|
43
|
+
@mode = i
|
44
|
+
ftp?.set_transfer_mode(
|
45
|
+
@mode, :be_quiet # Cascade the variable down into ftp_lib.rb.
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
# ========================================================================= #
|
50
|
+
# === do_use_binary_mode
|
51
|
+
# ========================================================================= #
|
52
|
+
def do_use_binary_mode
|
53
|
+
use_binary_mode(:be_quiet)
|
54
|
+
end
|
55
|
+
|
56
|
+
# ========================================================================= #
|
57
|
+
# === change
|
58
|
+
#
|
59
|
+
# This method can be used to change the main transfer mode.
|
60
|
+
# ========================================================================= #
|
61
|
+
def change(i)
|
62
|
+
case i
|
63
|
+
# ======================================================================= #
|
64
|
+
# === mode
|
65
|
+
# ======================================================================= #
|
66
|
+
when 'mode' # Change the mode that we use.
|
67
|
+
use_binary_mode
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# ========================================================================= #
|
72
|
+
# === set_run_mode
|
73
|
+
#
|
74
|
+
# This will set the run-mode. The run-mode can be either :standalone or
|
75
|
+
# :connected.
|
76
|
+
# ========================================================================= #
|
77
|
+
def set_run_mode(
|
78
|
+
i = :standalone
|
79
|
+
)
|
80
|
+
@run_mode = i
|
81
|
+
end
|
82
|
+
|
83
|
+
# ========================================================================= #
|
84
|
+
# === toggle_modes
|
85
|
+
# ========================================================================= #
|
86
|
+
def toggle_modes
|
87
|
+
if @mode == :ascii
|
88
|
+
set_mode :binary
|
89
|
+
else
|
90
|
+
set_mode :ascii
|
91
|
+
end
|
92
|
+
e mode?.to_s
|
93
|
+
end
|
94
|
+
|
95
|
+
# ========================================================================= #
|
96
|
+
# === use_ascii_mode
|
97
|
+
# ========================================================================= #
|
98
|
+
def use_ascii_mode(be_verbose = false)
|
99
|
+
e 'Using ascii mode now.' if be_verbose
|
100
|
+
set_mode :ascii
|
101
|
+
end
|
102
|
+
|
103
|
+
# ========================================================================= #
|
104
|
+
# === mode?
|
105
|
+
#
|
106
|
+
# @mode is a Symbol, hence we will not apply .to_s on it.
|
107
|
+
# ========================================================================= #
|
108
|
+
def mode?
|
109
|
+
return @mode
|
110
|
+
end
|
111
|
+
|
112
|
+
# ========================================================================= #
|
113
|
+
# === set_passive
|
114
|
+
# ========================================================================= #
|
115
|
+
def set_passive(
|
116
|
+
be_verbose = false
|
117
|
+
)
|
118
|
+
if be_verbose
|
119
|
+
e 'Enabling passive mode for FTP.'
|
120
|
+
end
|
121
|
+
ftp?.passive = true
|
122
|
+
end
|
123
|
+
|
124
|
+
end; end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# The Readline component will belong to class FtpParadise::InteractiveFtp.
|
6
|
+
#
|
7
|
+
# It would not make any sense to use it elsewhere within the FtpParadise
|
8
|
+
# project, as we don't have other interactive elements elsewhere.
|
9
|
+
# =========================================================================== #
|
10
|
+
# require 'ftp_paradise/interactive_ftp/readline.rb'
|
11
|
+
# =========================================================================== #
|
12
|
+
require 'ftp_paradise/base/prototype.rb'
|
13
|
+
|
14
|
+
module FtpParadise
|
15
|
+
|
16
|
+
class InteractiveFtp < Base # === FtpParadise::Interactive
|
17
|
+
|
18
|
+
begin
|
19
|
+
require 'readline'
|
20
|
+
rescue LoadError; end # Silent rescue.
|
21
|
+
|
22
|
+
# ========================================================================= #
|
23
|
+
# === use_readline?
|
24
|
+
# ========================================================================= #
|
25
|
+
def use_readline?
|
26
|
+
@use_readline
|
27
|
+
end; alias do_we_use_readline? use_readline? # === do_we_use_readline?
|
28
|
+
|
29
|
+
# ========================================================================= #
|
30
|
+
# === do_not_use_readline
|
31
|
+
# ========================================================================= #
|
32
|
+
def do_not_use_readline
|
33
|
+
@use_readline = false
|
34
|
+
end
|
35
|
+
|
36
|
+
# ========================================================================= #
|
37
|
+
# === enable_readline
|
38
|
+
# ========================================================================= #
|
39
|
+
def enable_readline
|
40
|
+
@use_readline = true
|
41
|
+
try_to_use_readline
|
42
|
+
end
|
43
|
+
|
44
|
+
# ========================================================================= #
|
45
|
+
# === try_to_use_readline
|
46
|
+
#
|
47
|
+
# This method ought to be called before we invoke the method menu().
|
48
|
+
# ========================================================================= #
|
49
|
+
def try_to_use_readline
|
50
|
+
if @use_readline
|
51
|
+
begin
|
52
|
+
require 'readline' # Using readline since August 2011.
|
53
|
+
setup_readline_completion
|
54
|
+
rescue LoadError
|
55
|
+
# =================================================================== #
|
56
|
+
# In this case the user can not use the readline-module.
|
57
|
+
# =================================================================== #
|
58
|
+
do_not_use_readline
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end; alias consider_using_the_readline_module try_to_use_readline # === consider_using_the_readline_module
|
62
|
+
|
63
|
+
# ========================================================================= #
|
64
|
+
# === setup_readline_completion
|
65
|
+
#
|
66
|
+
# Call this method to invoke completion support.
|
67
|
+
# ========================================================================= #
|
68
|
+
def setup_readline_completion
|
69
|
+
Readline.completion_case_fold = true # Ignore case on tab-completion.
|
70
|
+
Readline.completer_word_break_characters = "\n"
|
71
|
+
Readline.completion_append_character = ' '
|
72
|
+
# ======================================================================= #
|
73
|
+
# Act on Readline's completion functionality here. (readline tag)
|
74
|
+
#
|
75
|
+
# We will respond to these events specifically:
|
76
|
+
#
|
77
|
+
# - rcd
|
78
|
+
# - cd
|
79
|
+
# - upload
|
80
|
+
# - download
|
81
|
+
#
|
82
|
+
# ======================================================================= #
|
83
|
+
Readline.completion_proc = proc {|input|
|
84
|
+
_ = []
|
85
|
+
case input # case tag
|
86
|
+
# ===================================================================== #
|
87
|
+
# To test it, do:
|
88
|
+
# rcd AUS<TAB>
|
89
|
+
# ===================================================================== #
|
90
|
+
when /^rcd/,
|
91
|
+
/^rcd /,
|
92
|
+
/^rc/,
|
93
|
+
'rchange_dir',
|
94
|
+
'lcd',
|
95
|
+
'remote_change_directory'
|
96
|
+
result = @_.return_directories # This will return the remote directories only.
|
97
|
+
_ << result.map {|entry| input+' '+entry}
|
98
|
+
# ===================================================================== #
|
99
|
+
# === cd
|
100
|
+
# ===================================================================== #
|
101
|
+
when /^cd/,/^cd / # Fetch only directories.
|
102
|
+
_ << @_.return_local_directories
|
103
|
+
when /^upload/ # Act on upload.
|
104
|
+
return_local_files.each { |array| _ << array }
|
105
|
+
when /^download/ # Act on download.
|
106
|
+
@_.array_file_listing.each { |array| _ << array.first }
|
107
|
+
else # Default.
|
108
|
+
# _ << return_local_files # Disabled in June 2014 because it gives completions to things I did not ask for.
|
109
|
+
end
|
110
|
+
_ = _.flatten
|
111
|
+
_ # Return it here finally.
|
112
|
+
}
|
113
|
+
end
|
114
|
+
|
115
|
+
end; end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'ftp_paradise/interactive_ftp/remove.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module FtpParadise
|
8
|
+
|
9
|
+
class InteractiveFtp < Base
|
10
|
+
|
11
|
+
# ========================================================================= #
|
12
|
+
# === remove_local
|
13
|
+
# ========================================================================= #
|
14
|
+
def remove_local(i)
|
15
|
+
delete(i)
|
16
|
+
end
|
17
|
+
|
18
|
+
# ========================================================================= #
|
19
|
+
# === remove_remote_directory
|
20
|
+
#
|
21
|
+
# Use this method to remove a remote directory.
|
22
|
+
# ========================================================================= #
|
23
|
+
def remove_remote_directory(i)
|
24
|
+
e "Removing remote directory `#{sdir(i)}` next."
|
25
|
+
# ======================================================================= #
|
26
|
+
# Delegate to ftp?. :force_remove so we remove even non-empty directories.
|
27
|
+
# ======================================================================= #
|
28
|
+
ftp?.remove_directory(i, :force_remove)
|
29
|
+
end
|
30
|
+
|
31
|
+
# ========================================================================= #
|
32
|
+
# === remote_remove
|
33
|
+
#
|
34
|
+
# Use this if you wish to remove a remote file or a remote directory.
|
35
|
+
# ========================================================================= #
|
36
|
+
def remote_remove(i)
|
37
|
+
if i.is_a? Array
|
38
|
+
i.each {|entry| remote_remove(entry) }
|
39
|
+
else
|
40
|
+
i = i.to_s.strip # Added as of July 2014.
|
41
|
+
i = File.basename(i) if i.include? '/'
|
42
|
+
# ===================================================================== #
|
43
|
+
# The user may input numbers. If the input is a number, we will try to
|
44
|
+
# find the corresponding entry - but only if no remote directory or
|
45
|
+
# remote file exists with that name. Some directories may be named,
|
46
|
+
# e. g. "123456".
|
47
|
+
# ===================================================================== #
|
48
|
+
unless this_remote_entry_exists? i
|
49
|
+
i = convert_number_to_file(i) if i =~ /^\d+$/
|
50
|
+
end
|
51
|
+
# ===================================================================== #
|
52
|
+
# Next check for user input. If the user did input a '*', then we
|
53
|
+
# will expand that.
|
54
|
+
# ===================================================================== #
|
55
|
+
if i.include?('*') or i.include?('*.')
|
56
|
+
i = ftp?.array_file_listing.select {|entry|
|
57
|
+
entry[0].include? i.delete('*')
|
58
|
+
}
|
59
|
+
i.reject! {|line|
|
60
|
+
line == '.' or line == '..' # Reject '.' and '..' entries.
|
61
|
+
}
|
62
|
+
i.map! {|entry|
|
63
|
+
File.basename(entry)
|
64
|
+
} # ^^^ This is a bit hackish.
|
65
|
+
remote_remove(i)
|
66
|
+
else
|
67
|
+
# =================================================================== #
|
68
|
+
# We try to find out whether we have a directory or a file next.
|
69
|
+
# =================================================================== #
|
70
|
+
if is_dir?(i)
|
71
|
+
remove_remote_directory(i)
|
72
|
+
else # Assume it is a file.
|
73
|
+
remove_remote_file(i)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
# ========================================================================= #
|
80
|
+
# === remove_remote_file
|
81
|
+
#
|
82
|
+
# Use this method to attempt remove a remote file.
|
83
|
+
# ========================================================================= #
|
84
|
+
def remove_remote_file(i)
|
85
|
+
i[0,1] = ''.dup if i.start_with? '/' # We don't like starting "/" characters here.
|
86
|
+
e "Removing remote file `#{sfile(i)}` next." # We remove the remote file here.
|
87
|
+
begin
|
88
|
+
result = ftp?.remove_file(i)
|
89
|
+
e "Successfully removed remote file `#{sfile(result)}`."
|
90
|
+
rescue Net::FTPPermError => error
|
91
|
+
e 'Can not remove file `'+sfile(i)+'` as you are not '\
|
92
|
+
'the owner. ('+simp('Net::FTPPermError')+')'
|
93
|
+
pp error
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
end; end
|