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.

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,71 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'ftp_paradise/connection/notify.rb'
6
+ # =========================================================================== #
7
+ module FtpParadise
8
+
9
+ class Connection < Base
10
+
11
+ # ========================================================================= #
12
+ # === notify_the_user_about
13
+ #
14
+ # This method is a general "user notifier". It will notify the user
15
+ # about doing certain actions within the FtpParadise project.
16
+ # ========================================================================= #
17
+ def notify_the_user_about(
18
+ i, method
19
+ )
20
+ case method
21
+ # ======================================================================= #
22
+ # === :set_transfer_mode
23
+ # ======================================================================= #
24
+ when :set_transfer_mode
25
+ opnn; e "Setting mode to #{orange(i.to_s)} now."
26
+ # ======================================================================= #
27
+ # === :remove_remote_files
28
+ # ======================================================================= #
29
+ when :remove_remote_files
30
+ opnn; e "Deleting the remote file `#{sdir(i)}` now."
31
+ # ======================================================================= #
32
+ # === :upload_binary_file
33
+ # ======================================================================= #
34
+ when :upload_binary_file
35
+ opnn; e 'Now trying to upload the binary file `'+sfile(i)+'`'
36
+ opnn; e 'to the remote host `'+sfancy(remote_host?)+'`.'
37
+ # ======================================================================= #
38
+ # === :create_this_remote_directory
39
+ # ======================================================================= #
40
+ when :create_this_remote_directory
41
+ opnn; e 'Creating the remote directory `'+sdir(i)+'` now.'
42
+ # ======================================================================= #
43
+ # === :remote_cd
44
+ # ======================================================================= #
45
+ when :remote_cd
46
+ opnn; e 'Trying to remote-change directory into `'+sdir(i)+'`.'
47
+ # ======================================================================= #
48
+ # === :download_this_remote_file
49
+ # ======================================================================= #
50
+ when :download_this_remote_file
51
+ opnn; e "Downloading the remote file `#{sdir(i)}` now."
52
+ # ======================================================================= #
53
+ # === :upload_this_text_file
54
+ # ======================================================================= #
55
+ when :upload_this_text_file
56
+ opnn; e 'Uploading the local text file `'+sfile(i)+'` to '\
57
+ 'the remote host at `'+sfancy(remote_pwd?)+'`.'
58
+ # ======================================================================= #
59
+ # === :create_remote_file
60
+ # ======================================================================= #
61
+ when :create_remote_file
62
+ opnn; e 'Creating the remote file `'+sdir(i)+'` now.'
63
+ # ======================================================================= #
64
+ # === :remove_remote_directory
65
+ # ======================================================================= #
66
+ when :remove_remote_directory
67
+ opnn; e 'Removing the remote directory `'+sdir(i)+'` now.'
68
+ end
69
+ end
70
+
71
+ end; end
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'ftp_paradise/connection/password.rb'
6
+ # =========================================================================== #
7
+ module FtpParadise
8
+
9
+ class Connection < Base
10
+
11
+ require 'ftp_paradise/toplevel_methods/password.rb'
12
+
13
+ # ========================================================================= #
14
+ # === password?
15
+ # ========================================================================= #
16
+ def password?
17
+ FtpParadise.password?.to_s
18
+ end; alias password password? # === password
19
+
20
+ # ========================================================================= #
21
+ # === set_password
22
+ #
23
+ # Use only this method when attempting to modify the @password.
24
+ #
25
+ # This @ivar keeps track of the password we will use.
26
+ # ========================================================================= #
27
+ def set_password(
28
+ i = :try_to_use_a_default_password
29
+ )
30
+ case i
31
+ when :try_to_use_a_default_password,
32
+ :default
33
+ if FtpParadise::RoebeFtpConstants::BPLACED
34
+ _ = FtpParadise::RoebeFtpConstants::BPLACED[2]
35
+ _.chop! if _.end_with? '_'
36
+ i = _
37
+ end
38
+ when :anonymous
39
+ i = nil
40
+ else
41
+ i = i.to_s
42
+ end
43
+ FtpParadise.set_password(i)
44
+ i # Return the password here as well, so that we can use it for assignments.
45
+ end; alias password= set_password # === password=
46
+
47
+ end; end
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'ftp_paradise/connection/port.rb'
6
+ # =========================================================================== #
7
+ module FtpParadise
8
+
9
+ class Connection < Base
10
+
11
+ require 'ftp_paradise/toplevel_methods/port.rb'
12
+ require 'ftp_paradise/connection/ftp_object.rb'
13
+
14
+ # ========================================================================= #
15
+ # === set_port
16
+ #
17
+ # Use this method to set the port. The port will be stored on the
18
+ # toplevel-"namespace".
19
+ # ========================================================================= #
20
+ def set_port(
21
+ i = DEFAULT_PORT
22
+ )
23
+ FtpParadise.set_port(i)
24
+ end
25
+
26
+ # ========================================================================= #
27
+ # === port?
28
+ # ========================================================================= #
29
+ def port?
30
+ FtpParadise.port?.to_s
31
+ end; alias port port? # === port
32
+
33
+ end; end
@@ -0,0 +1,72 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'ftp_paradise/connection/remote_pwd.rb'
6
+ # =========================================================================== #
7
+ module FtpParadise
8
+
9
+ class Connection < FtpParadise::Base
10
+
11
+ require 'ftp_paradise/connection/remote_url.rb'
12
+
13
+ # ========================================================================= #
14
+ # === remote_pwd
15
+ # ========================================================================= #
16
+ def remote_pwd
17
+ ftp_object?.pwd
18
+ end; alias rpwd remote_pwd # === rpwd
19
+ alias getdir remote_pwd # === getdir
20
+
21
+ # ========================================================================= #
22
+ # === return_remote_pwd
23
+ #
24
+ # This method will return the (remote) pwd, including the remote working
25
+ # directory - including the subpath..
26
+ #
27
+ # This method will ensure that a trailing '/' will be returned here.
28
+ #
29
+ # The official documentation can be seen here:
30
+ # https://ruby-doc.org/stdlib/libdoc/net/ftp/rdoc/Net/FTP.html#method-i-pwd
31
+ # ========================================================================= #
32
+ def return_remote_pwd
33
+ begin
34
+ if is_connected?
35
+ remote_pwd = remote_url?.dup
36
+ # ===================================================================== #
37
+ # Need to safeguard, in the event that we are not connected to a
38
+ # remote FTP server.
39
+ # ===================================================================== #
40
+ remote_pwd << ftp_object?.pwd.to_s if ftp_object?
41
+ remote_pwd << '/'
42
+ return rds(remote_pwd)
43
+ else
44
+ opnn; e 'No FTP connection is open.'
45
+ ''
46
+ end
47
+ rescue Net::FTPReplyError
48
+ opnn; e 'Error Net::FTPReplyError received. May be due to user interrupting.'
49
+ opnn; e 'Exiting now at once either way.'
50
+ exit
51
+ rescue SystemExit, Interrupt
52
+ opnn; e 'User requested to exit, thus exiting now.'
53
+ exit
54
+ end
55
+ end; alias pwd? return_remote_pwd # === pwd?
56
+ alias pwd return_remote_pwd # === pwd (pwd tag)
57
+ alias getdir return_remote_pwd # === get_dir
58
+ alias remote_pwd return_remote_pwd # === remote_pwd
59
+ alias remote_pwd? return_remote_pwd # === remote_pwd?
60
+ alias connected_to? return_remote_pwd # === connected_to?
61
+ alias remote? return_remote_pwd # === remote?
62
+ alias base_dir? return_remote_pwd # === base_dir?
63
+ alias remote_directory? return_remote_pwd # === remote_directory?
64
+ alias remote_dir? return_remote_pwd # === remote_dir?
65
+ alias remote_path? return_remote_pwd # === remote_path?
66
+ alias return_subdirectory return_remote_pwd # === return_subdirectory
67
+ alias current_directory return_remote_pwd # === current_directory
68
+ alias return_remote_dir return_remote_pwd # === return_remote_dir
69
+ alias get_remote_dir return_remote_pwd # === get_remote_dir
70
+ alias remote_host? return_remote_pwd # === remote_host?
71
+
72
+ end; end
@@ -0,0 +1,163 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'ftp_paradise/connection/remote_url.rb'
6
+ # =========================================================================== #
7
+ module FtpParadise
8
+
9
+ class Connection < Base
10
+
11
+ require 'ftp_paradise/toplevel_methods/remote_url.rb'
12
+
13
+ # ========================================================================= #
14
+ # === remote_url?
15
+ #
16
+ # This method is guaranteed to return a String.
17
+ # ========================================================================= #
18
+ def remote_url?
19
+ begin
20
+ return FtpParadise.remote_url?.to_s
21
+ rescue Interrupt
22
+ exit # User interrupted, so we exit as requested.
23
+ rescue Exception => error
24
+ opnn; e 'We did encounter an error in the method '+
25
+ simp(__method__.to_s)
26
+ opnn; pp error
27
+ return error.to_s # Return that exception.
28
+ end
29
+ end; alias remote_host? remote_url? # === remote_host?
30
+ alias remote_url remote_url? # === remote_url
31
+ alias url? remote_url? # === url?
32
+ alias host? remote_url? # === host?
33
+ alias host remote_url? # === host
34
+
35
+ # ========================================================================= #
36
+ # === set_remote_url
37
+ #
38
+ # This method will do some sanitizing before it sets a proper and
39
+ # valid hostname. Remember to keep the 'default' entry at the
40
+ # current main FTP host you use.
41
+ # ========================================================================= #
42
+ def set_remote_url(
43
+ i = :default,
44
+ be_verbose = true
45
+ )
46
+ i = :default? if i.nil?
47
+ if i.is_a? Hash # Handle Hash as input here.
48
+ if i.has_key?(:to)
49
+ i = i[:to]
50
+ end
51
+ end
52
+ # ======================================================================= #
53
+ # The next block is mostly for my custom constants.
54
+ # You can simply pass in your own Hash.
55
+ # ======================================================================= #
56
+ case i # Do some sanitizing. This is a String here. (case tag)
57
+ # ======================================================================= #
58
+ # === bplaced
59
+ # ======================================================================= #
60
+ when /^-?-?bplaced$/i,
61
+ 'default'
62
+ set_data(BPLACED)
63
+ i = BPLACED.first
64
+ # ======================================================================= #
65
+ # === shevy
66
+ # ======================================================================= #
67
+ when /^-?-?shevy$/i
68
+ set_data(BPLACED)
69
+ i = BPLACED.first
70
+ # ======================================================================= #
71
+ # === ?
72
+ # ======================================================================= #
73
+ when '?'
74
+ feedback_login_hosts
75
+ # ======================================================================= #
76
+ # === uniwien_homepage
77
+ # ======================================================================= #
78
+ when /^uniwien_?homepage/
79
+ set_data(UNIWIEN_HOMEPAGE)
80
+ i = UNIWIEN_HOMEPAGE.first
81
+ # ======================================================================= #
82
+ # === unet
83
+ # ======================================================================= #
84
+ when 'unet','uni','uniftp'
85
+ set_data(UNIVIE)
86
+ i = UNIVIE.first
87
+ # ======================================================================= #
88
+ # === a1
89
+ # ======================================================================= #
90
+ when /^a1/
91
+ set_data(A1)
92
+ i = A1.first
93
+ # ======================================================================= #
94
+ # === byte
95
+ # ======================================================================= #
96
+ when /^byte/ # This also includese bytehost.
97
+ set_data(BYTEHOST)
98
+ i = BYTEHOST.first
99
+ # ======================================================================= #
100
+ # === zerofees
101
+ # ======================================================================= #
102
+ when 'ZEROFEES','zero','ZERO'
103
+ set_data(ZEROFEES)
104
+ i = ZEROFEES.first
105
+ # ======================================================================= #
106
+ # === ucoz
107
+ # ======================================================================= #
108
+ when 'ucoz','UCOZ','LAST',/tanriel/i,
109
+ 'last'
110
+ set_data(UCOZ)
111
+ i = UCOZ.first
112
+ end
113
+ case i.to_s
114
+ # ======================================================================= #
115
+ # === shevy
116
+ # ======================================================================= #
117
+ when 'shevy','5','default' # Current default entry.
118
+ i = SQUARE7.first
119
+ # ======================================================================= #
120
+ # === a1
121
+ # ======================================================================= #
122
+ when '1','a1'
123
+ i = A1.first
124
+ # ======================================================================= #
125
+ # === unet
126
+ # ======================================================================= #
127
+ when '2','unet','uni','uniftp'
128
+ i = UNIVIE.first
129
+ # ======================================================================= #
130
+ # === geas
131
+ # ======================================================================= #
132
+ when '3','geas'
133
+ i = GEAS.first
134
+ # ======================================================================= #
135
+ # === byte
136
+ # ======================================================================= #
137
+ when '4','byte'
138
+ i = BYTEHOST.first
139
+ end
140
+ i = i.to_s # Need a String here.
141
+ # ======================================================================= #
142
+ # === Provide more information to the user
143
+ # ======================================================================= #
144
+ if debug?
145
+ opnn; e "The remote URL was set to: #{sfancy(i)}"
146
+ end
147
+ if be_verbose
148
+ e "Setting url to #{sfancy(i)} now."
149
+ end
150
+ FtpParadise.set_remote_url(i)
151
+ # ======================================================================= #
152
+ # And we will always initialize a new ftp-object as well, whenever
153
+ # we call this method:
154
+ # ======================================================================= #
155
+ initialize_a_new_net_ftp_object_with_this_remote_url(i)
156
+ end; alias set_this_host set_remote_url # === set_this_host
157
+ alias set_host set_remote_url # === set_host
158
+ alias set_url set_remote_url # === set_url
159
+ alias host= set_remote_url # === host=
160
+ alias url= set_remote_url # === url=
161
+ alias set_remote_host set_remote_url # === set_remote_host
162
+
163
+ end; end
@@ -0,0 +1,143 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'ftp_paradise/connection/remove.rb'
6
+ # =========================================================================== #
7
+ module FtpParadise
8
+
9
+ class Connection < Base
10
+
11
+ # ========================================================================= #
12
+ # === remove (remove tag)
13
+ # ========================================================================= #
14
+ def remove(i)
15
+ if i.is_a? Array
16
+ i.each {|entry| remove(entry) }
17
+ else
18
+ if is_a_directory?(i)
19
+ remove_remote_directory(i)
20
+ elsif is_a_file?(i)
21
+ remove_remote_file(i, be_verbose?)
22
+ end
23
+ end
24
+ end
25
+
26
+ # ========================================================================= #
27
+ # === remove_remote_file
28
+ #
29
+ # Remove a (remote) file, via the delete() method of the FTP protocol.
30
+ #
31
+ # Note that this method will only delete files.
32
+ #
33
+ # The official documentation for the Ruby-FTP delete() method can be
34
+ # found here:
35
+ #
36
+ # https://www.ruby-doc.org/stdlib/libdoc/net/ftp/rdoc/Net/FTP.html#method-i-delete
37
+ #
38
+ # ========================================================================= #
39
+ def remove_remote_file(
40
+ i,
41
+ be_verbose = be_verbose?
42
+ )
43
+ case be_verbose
44
+ when :be_verbose
45
+ be_verbose = true
46
+ end
47
+ if i.is_a? Array
48
+ i.each {|entry| remove_remote_file(entry, be_verbose) }
49
+ else
50
+ if does_this_remote_file_exist?(File.basename(i))
51
+ i = File.basename(i)
52
+ if i =~ /^\d+$/ # if is a number
53
+ update_file_listing
54
+ _ = return_remote_file_listing[i.to_i - 1].first
55
+ _ = File.basename(_)
56
+ e "Performing a substitution of #{sfancy(i)}"\
57
+ " to #{simp(_)}."
58
+ i = _
59
+ end
60
+ if be_verbose
61
+ notify_the_user_about(i, __method__)
62
+ end
63
+ ftp_object?.delete(i)
64
+ update_file_listing
65
+ return i # Also return the file that was deleted.
66
+ else
67
+ opnn; e "No remote file called `#{sfile(i)}` was "\
68
+ "found at `#{sfancy(remote_pwd)}`."
69
+ end
70
+ end
71
+ end; alias remote_remove remove_remote_file # === remote_remove
72
+ alias remote_remove_files remove_remote_file # === remote_remove_files
73
+ alias remote_remove_file remove_remote_file # === remote_remove_files
74
+ alias delete remove_remote_file # === delete
75
+ alias remove_file remove_remote_file # === remove_file
76
+ alias rm_file remove_remote_file # === rm_file
77
+ alias rmfile remove_remote_file # === rmfile
78
+
79
+ # ========================================================================= #
80
+ # === original_delete
81
+ #
82
+ # This method will remove the file, without doing any additional
83
+ # checks.
84
+ # ========================================================================= #
85
+ def original_delete(i)
86
+ ftp_object?.delete(i)
87
+ end
88
+
89
+ # ========================================================================= #
90
+ # === remove_remote_directory
91
+ #
92
+ # This method will remove a remote directory. For this to work, as
93
+ # operation, the remote directory has to exist.
94
+ #
95
+ # This operation may fail e. g. when the remote directory is not empty.
96
+ # This explains why we attempt to rescue some errors.
97
+ # ========================================================================= #
98
+ def remove_remote_directory(
99
+ i,
100
+ be_verbose = be_verbose?,
101
+ force_remove = false
102
+ )
103
+ case force_remove
104
+ when :force_remove
105
+ force_remove = true
106
+ when :do_not_force_remove
107
+ force_remove = false
108
+ end
109
+ if i.is_a? Array
110
+ i.each {|entry| remove_remote_directory(entry, be_verbose) }
111
+ else
112
+ if be_verbose
113
+ notify_the_user_about(i, __method__)
114
+ end
115
+ if is_a_directory? i
116
+ begin
117
+ ftp_object?.rmdir(i)
118
+ rescue Net::FTPPermError => error
119
+ opnn; e swarn('We could not remove the remote directory at ')+
120
+ sdir(i)+swarn(' as it is not empty.')
121
+ pp error
122
+ if force_remove
123
+ opnn; e 'We will now try to enter into this directory'
124
+ opnn; e 'and then remove all files of that directory.'
125
+ rcd(this_dir)
126
+ update_file_listing
127
+ all_remote_files?.each {|file| remove(file) } # Now it should be removed.
128
+ rcd('..') # Go back again.
129
+ rmdir(i, be_verbose, :do_not_force_remove) # But we won't force again, to avoid recursive loops.
130
+ opnn; e "The remote directory at #{sdir(i)} has been removed."
131
+ end
132
+ end
133
+ else
134
+ if be_verbose
135
+ opnn; e "The given input #{sfancy(i)} is not a directory."
136
+ end
137
+ end
138
+ end
139
+ end; alias rmdir remove_remote_directory # === rmdir
140
+ alias remove_these_remote_directories remove_remote_directory # === remove_these_remote_directories
141
+ alias remove_directory remove_remote_directory # === remove_directory
142
+
143
+ end; end