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.
Files changed (119) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +319 -0
  3. data/bin/create_remote_directory +9 -0
  4. data/bin/ftp_get +17 -0
  5. data/bin/ftp_gtk3 +7 -0
  6. data/bin/ftp_upload +42 -0
  7. data/bin/ftp_upload_binary +18 -0
  8. data/bin/iftp +7 -0
  9. data/bin/remote_remove +28 -0
  10. data/doc/README.gen +302 -0
  11. data/doc/todo/TODO_FOR_FTP_PARADISE_PROJECT.md +79 -0
  12. data/ftp_paradise.gemspec +122 -0
  13. data/lib/ftp_paradise.rb +5 -0
  14. data/lib/ftp_paradise/base/cliner.rb +23 -0
  15. data/lib/ftp_paradise/base/colours.rb +83 -0
  16. data/lib/ftp_paradise/base/prototype.rb +171 -0
  17. data/lib/ftp_paradise/base/reset.rb +29 -0
  18. data/lib/ftp_paradise/colours/colours.rb +141 -0
  19. data/lib/ftp_paradise/colours/use_colours.rb +76 -0
  20. data/lib/ftp_paradise/configuration/configuration.rb +49 -0
  21. data/lib/ftp_paradise/connection/README.md +1 -0
  22. data/lib/ftp_paradise/connection/connection.rb +35 -0
  23. data/lib/ftp_paradise/connection/constants.rb +46 -0
  24. data/lib/ftp_paradise/connection/data.rb +164 -0
  25. data/lib/ftp_paradise/connection/debug.rb +78 -0
  26. data/lib/ftp_paradise/connection/directory_handling.rb +271 -0
  27. data/lib/ftp_paradise/connection/do_login.rb +108 -0
  28. data/lib/ftp_paradise/connection/download.rb +86 -0
  29. data/lib/ftp_paradise/connection/file_handling.rb +174 -0
  30. data/lib/ftp_paradise/connection/ftp_object.rb +21 -0
  31. data/lib/ftp_paradise/connection/initialize.rb +88 -0
  32. data/lib/ftp_paradise/connection/initialize_a_new_net_ftp_object_with_this_url.rb +20 -0
  33. data/lib/ftp_paradise/connection/is_connected.rb +46 -0
  34. data/lib/ftp_paradise/connection/misc.rb +474 -0
  35. data/lib/ftp_paradise/connection/notify.rb +71 -0
  36. data/lib/ftp_paradise/connection/password.rb +47 -0
  37. data/lib/ftp_paradise/connection/port.rb +33 -0
  38. data/lib/ftp_paradise/connection/remote_pwd.rb +72 -0
  39. data/lib/ftp_paradise/connection/remote_url.rb +164 -0
  40. data/lib/ftp_paradise/connection/remove.rb +143 -0
  41. data/lib/ftp_paradise/connection/reset.rb +78 -0
  42. data/lib/ftp_paradise/connection/run.rb +18 -0
  43. data/lib/ftp_paradise/connection/set_array_available_hosts.rb +27 -0
  44. data/lib/ftp_paradise/connection/set_input.rb +18 -0
  45. data/lib/ftp_paradise/connection/show.rb +153 -0
  46. data/lib/ftp_paradise/connection/sync_ftp_object_onto_the_main_namespace.rb +24 -0
  47. data/lib/ftp_paradise/connection/transfer_mode.rb +163 -0
  48. data/lib/ftp_paradise/connection/upload.rb +253 -0
  49. data/lib/ftp_paradise/connection/use_default_dataset.rb +40 -0
  50. data/lib/ftp_paradise/connection/username.rb +42 -0
  51. data/lib/ftp_paradise/constants/constants.rb +19 -0
  52. data/lib/ftp_paradise/constants/misc.rb +57 -0
  53. data/lib/ftp_paradise/constants/namespace.rb +14 -0
  54. data/lib/ftp_paradise/constants/newline.rb +14 -0
  55. data/lib/ftp_paradise/constants/roebe.rb +31 -0
  56. data/lib/ftp_paradise/constants/roebe_ftp_constants.rb +233 -0
  57. data/lib/ftp_paradise/entry/entry.rb +300 -0
  58. data/lib/ftp_paradise/gui/gtk2/ftp_paradise.rb +34 -0
  59. data/lib/ftp_paradise/gui/gtk3/ftp_paradise.rb +34 -0
  60. data/lib/ftp_paradise/gui/shared_code/ftp_paradise/ftp_paradise_module.rb +709 -0
  61. data/lib/ftp_paradise/images/connection_image.png +0 -0
  62. data/lib/ftp_paradise/interactive_ftp/constants.rb +103 -0
  63. data/lib/ftp_paradise/interactive_ftp/directory_handling.rb +216 -0
  64. data/lib/ftp_paradise/interactive_ftp/help.rb +50 -0
  65. data/lib/ftp_paradise/interactive_ftp/initialize.rb +27 -0
  66. data/lib/ftp_paradise/interactive_ftp/interactive_ftp.rb +998 -0
  67. data/lib/ftp_paradise/interactive_ftp/main_loop.rb +51 -0
  68. data/lib/ftp_paradise/interactive_ftp/menu.rb +786 -0
  69. data/lib/ftp_paradise/interactive_ftp/misc.rb +208 -0
  70. data/lib/ftp_paradise/interactive_ftp/mode.rb +124 -0
  71. data/lib/ftp_paradise/interactive_ftp/readline.rb +113 -0
  72. data/lib/ftp_paradise/interactive_ftp/remove.rb +97 -0
  73. data/lib/ftp_paradise/interactive_ftp/reset.rb +90 -0
  74. data/lib/ftp_paradise/interactive_ftp/run.rb +22 -0
  75. data/lib/ftp_paradise/interactive_ftp/show.rb +184 -0
  76. data/lib/ftp_paradise/interactive_ftp/upload.rb +90 -0
  77. data/lib/ftp_paradise/interactive_ftp/user_input.rb +53 -0
  78. data/lib/ftp_paradise/project/project.rb +64 -0
  79. data/lib/ftp_paradise/requires/common_basic_requires.rb +14 -0
  80. data/lib/ftp_paradise/requires/common_external_requires.rb +9 -0
  81. data/lib/ftp_paradise/requires/require_the_constants.rb +7 -0
  82. data/lib/ftp_paradise/requires/require_the_ftp_paradise_project.rb +18 -0
  83. data/lib/ftp_paradise/requires/require_the_ftp_paradise_project_with_the_GUI_bindings.rb +10 -0
  84. data/lib/ftp_paradise/requires/require_the_toplevel_methods.rb +24 -0
  85. data/lib/ftp_paradise/toplevel_methods/can_connect_to_remote_site.rb +28 -0
  86. data/lib/ftp_paradise/toplevel_methods/clear_user_dataset.rb +28 -0
  87. data/lib/ftp_paradise/toplevel_methods/connect.rb +50 -0
  88. data/lib/ftp_paradise/toplevel_methods/data.rb +31 -0
  89. data/lib/ftp_paradise/toplevel_methods/determine_user_dataset_from_this_hash.rb +37 -0
  90. data/lib/ftp_paradise/toplevel_methods/directory_related_actions.rb +33 -0
  91. data/lib/ftp_paradise/toplevel_methods/e.rb +16 -0
  92. data/lib/ftp_paradise/toplevel_methods/file_related_actions.rb +49 -0
  93. data/lib/ftp_paradise/toplevel_methods/ftp_object.rb +270 -0
  94. data/lib/ftp_paradise/toplevel_methods/is_on_roebe.rb +20 -0
  95. data/lib/ftp_paradise/toplevel_methods/login_name.rb +49 -0
  96. data/lib/ftp_paradise/toplevel_methods/misc.rb +16 -0
  97. data/lib/ftp_paradise/toplevel_methods/opn.rb +24 -0
  98. data/lib/ftp_paradise/toplevel_methods/password.rb +50 -0
  99. data/lib/ftp_paradise/toplevel_methods/port.rb +41 -0
  100. data/lib/ftp_paradise/toplevel_methods/rds.rb +18 -0
  101. data/lib/ftp_paradise/toplevel_methods/remote_url.rb +57 -0
  102. data/lib/ftp_paradise/toplevel_methods/time.rb +45 -0
  103. data/lib/ftp_paradise/toplevel_methods/upload_and_download.rb +108 -0
  104. data/lib/ftp_paradise/version/version.rb +19 -0
  105. data/lib/ftp_paradise/www/public/css/style.css +3 -0
  106. data/lib/ftp_paradise/www/sinatra_web_interface.rb +242 -0
  107. data/lib/ftp_paradise/www/views/index.slim +3 -0
  108. data/lib/ftp_paradise/www/views/layout.slim +11 -0
  109. data/lib/ftp_paradise/www/web_interface.cgi +34 -0
  110. data/lib/ftp_paradise/yaml/automatically_connect_on_startup_of_the_interactive_ftp_shell.yml +1 -0
  111. data/lib/ftp_paradise/yaml/debug.yml +1 -0
  112. data/lib/ftp_paradise/yaml/open_in_default_editor.yml +1 -0
  113. data/lib/ftp_paradise/yaml/show_full_names.yml +1 -0
  114. data/lib/ftp_paradise/yaml/use_colours.yml +1 -0
  115. data/test/testing_ftp_paradise.rb +94 -0
  116. data/test/testing_minimal_pure_net_ftp_example_to_connect.rb +28 -0
  117. data/test/testing_the_ftp_connection_component.rb +70 -0
  118. data/test/testing_upload_a_local_directory.rb +10 -0
  119. metadata +336 -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
+ module FtpParadise
8
+
9
+ class InteractiveFtp
10
+
11
+ require 'ftp_paradise/interactive_ftp/directory_handling.rb'
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
+ # === remote_remove_file
149
+ # ========================================================================= #
150
+ def remote_remove_file(
151
+ i = @first_argument
152
+ )
153
+ if i.is_a? Array
154
+ i.each {|entry| remote_remove_file(entry) }
155
+ else
156
+ e "Trying to remove `#{sfile(i)}` next:"
157
+ @ftp.delete(i)
158
+ end
159
+ end; alias remote_remove_files remote_remove_file # === remote_remove_files
160
+
161
+ # ========================================================================= #
162
+ # === display_file
163
+ #
164
+ # Use this method to display a file in question.
165
+ # ========================================================================= #
166
+ def display_file(i)
167
+ if File.exist? i
168
+ _ = File.readlines(i).join
169
+ e _
170
+ else
171
+ ewarn "File #{sfile(i)} does not exist."
172
+ end
173
+ end
174
+
175
+ # ========================================================================= #
176
+ # === report_version
177
+ # ========================================================================= #
178
+ def report_version
179
+ e sfancy(FtpParadise::VERSION)
180
+ end
181
+
182
+ # ========================================================================= #
183
+ # === all_arguments?
184
+ #
185
+ # The alias a? may be an easier wrapper over @all_arguments.
186
+ # ========================================================================= #
187
+ def all_arguments?
188
+ @all_arguments
189
+ end; alias a? all_arguments? # === a?
190
+
191
+ # ========================================================================= #
192
+ # === try_to_chmod_this_remote_file
193
+ # ========================================================================= #
194
+ def try_to_chmod_this_remote_file(
195
+ filename, chmod_value_to_use = '0777'
196
+ )
197
+ e "Trying to chmod the remote file #{filename} next."
198
+ ftp?.sendcmd("SITE CHMOD #{chmod_value_to_use} #{filename}")
199
+ end
200
+
201
+ # ========================================================================= #
202
+ # === password?
203
+ # ========================================================================= #
204
+ def password?
205
+ FtpParadise.password?
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::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,113 @@
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
+ module FtpParadise
13
+
14
+ class InteractiveFtp # === FtpParadise::Interactive
15
+
16
+ begin
17
+ require 'readline'
18
+ rescue LoadError; end # Silent rescue.
19
+
20
+ # ========================================================================= #
21
+ # === use_readline?
22
+ # ========================================================================= #
23
+ def use_readline?
24
+ @use_readline
25
+ end; alias do_we_use_readline? use_readline? # === do_we_use_readline?
26
+
27
+ # ========================================================================= #
28
+ # === do_not_use_readline
29
+ # ========================================================================= #
30
+ def do_not_use_readline
31
+ @use_readline = false
32
+ end
33
+
34
+ # ========================================================================= #
35
+ # === enable_readline
36
+ # ========================================================================= #
37
+ def enable_readline
38
+ @use_readline = true
39
+ try_to_use_readline
40
+ end
41
+
42
+ # ========================================================================= #
43
+ # === try_to_use_readline
44
+ #
45
+ # This method ought to be called before we invoke the method menu().
46
+ # ========================================================================= #
47
+ def try_to_use_readline
48
+ if @use_readline
49
+ begin
50
+ require 'readline' # Using readline since August 2011.
51
+ setup_readline_completion
52
+ rescue LoadError
53
+ # =================================================================== #
54
+ # In this case the user can not use the readline-module.
55
+ # =================================================================== #
56
+ do_not_use_readline
57
+ end
58
+ end
59
+ end; alias consider_using_the_readline_module try_to_use_readline # === consider_using_the_readline_module
60
+
61
+ # ========================================================================= #
62
+ # === setup_readline_completion
63
+ #
64
+ # Call this method to invoke completion support.
65
+ # ========================================================================= #
66
+ def setup_readline_completion
67
+ Readline.completion_case_fold = true # Ignore case on tab-completion.
68
+ Readline.completer_word_break_characters = "\n"
69
+ Readline.completion_append_character = ' '
70
+ # ======================================================================= #
71
+ # Act on Readline's completion functionality here. (readline tag)
72
+ #
73
+ # We will respond to these events specifically:
74
+ #
75
+ # - rcd
76
+ # - cd
77
+ # - upload
78
+ # - download
79
+ #
80
+ # ======================================================================= #
81
+ Readline.completion_proc = proc {|input|
82
+ _ = []
83
+ case input # case tag
84
+ # ===================================================================== #
85
+ # To test it, do:
86
+ # rcd AUS<TAB>
87
+ # ===================================================================== #
88
+ when /^rcd/,
89
+ /^rcd /,
90
+ /^rc/,
91
+ 'rchange_dir',
92
+ 'lcd',
93
+ 'remote_change_directory'
94
+ result = @_.return_directories # This will return the remote directories only.
95
+ _ << result.map {|entry| input+' '+entry}
96
+ # ===================================================================== #
97
+ # === cd
98
+ # ===================================================================== #
99
+ when /^cd/,/^cd / # Fetch only directories.
100
+ _ << @_.return_local_directories
101
+ when /^upload/ # Act on upload.
102
+ return_local_files.each { |array| _ << array }
103
+ when /^download/ # Act on download.
104
+ @_.array_file_listing.each { |array| _ << array.first }
105
+ else # Default.
106
+ # _ << return_local_files # Disabled in June 2014 because it gives completions to things I did not ask for.
107
+ end
108
+ _ = _.flatten
109
+ _ # Return it here finally.
110
+ }
111
+ end
112
+
113
+ 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
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