ftp_paradise 1.3.8

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.

Potentially problematic release.


This version of ftp_paradise might be problematic. Click here for more details.

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