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,271 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'ftp_paradise/connection/directory_handling.rb'
6
+ # =========================================================================== #
7
+ module FtpParadise
8
+
9
+ class Connection
10
+
11
+ require 'ftp_paradise/connection/remote_pwd.rb'
12
+ require 'ftp_paradise/connection/file_handling.rb'
13
+
14
+ # ========================================================================= #
15
+ # === report_current_remote_dir
16
+ #
17
+ # Gives you the current dir.
18
+ # ========================================================================= #
19
+ def report_current_remote_dir(
20
+ be_verbose = be_verbose?
21
+ )
22
+ begin
23
+ if be_verbose
24
+ opnn; e 'The remote directory is:'
25
+ e " #{sdir(return_remote_pwd)}"
26
+ end
27
+ rescue Exception => error
28
+ opnn; e error.class
29
+ opnn; e error
30
+ end
31
+ end; alias report_remote_directory report_current_remote_dir # === report_remote_directory
32
+ alias dir? report_current_remote_dir # === dir?
33
+ alias report_remote_pwd report_current_remote_dir # === report_remote_pwd
34
+
35
+ # ========================================================================= #
36
+ # === remote_chdir (cd tag, chdir tag)
37
+ #
38
+ # This method allows us to cd to another remote directory, on the
39
+ # remote FTP server (our main connection).
40
+ #
41
+ # The method must be able to check whether we are connected to the
42
+ # remote host.
43
+ # ========================================================================= #
44
+ def remote_chdir(
45
+ i,
46
+ be_verbose = be_verbose?
47
+ )
48
+ i = i.dup if i.frozen?
49
+ # ======================================================================= #
50
+ # Sanitize odd entries ending with ':'
51
+ # ======================================================================= #
52
+ i[-1,1] = '/' if i.end_with? ':'
53
+ i = rds("#{i}/") # <- Always ensure that a '/' is the last character.
54
+ if be_verbose
55
+ notify_the_user_about(i, __method__)
56
+ end
57
+ if is_connected?
58
+ # ===================================================================== #
59
+ # If we cd to a non-existing target, the exception Net::FTPPermError
60
+ # will be raised.
61
+ # ===================================================================== #
62
+ begin
63
+ ftp_object?.chdir(i)
64
+ update_remote_file_listing
65
+ # ===================================================================== #
66
+ # The user may have insufficient permissions:
67
+ # ===================================================================== #
68
+ rescue Net::FTPPermError => error
69
+ pp error
70
+ rescue Net::ReadTimeout => error
71
+ opnn; e 'An error was encountered in the method '\
72
+ 'remote_chdir().'
73
+ opnn; e 'The error-class was Net::ReadTimeout.'
74
+ e
75
+ opnn; e 'The specific error will be displayed next.'
76
+ e
77
+ pp error
78
+ end
79
+ else
80
+ opnn; e 'We are not connected to a remote host right now.'
81
+ opnn; e 'Thus we can not change the directory.'
82
+ end
83
+ report_current_remote_dir if be_verbose # right now mandatory
84
+ end; alias rcd remote_chdir # === rcd
85
+ alias remote_cd remote_chdir # === remote_cd
86
+ alias chdir remote_chdir # === chdir
87
+ alias cd remote_chdir # === cd
88
+ alias chdir remote_chdir # === chdir
89
+ alias rcd remote_chdir # === rcd
90
+ alias change_directory remote_chdir # === change_directory
91
+ alias change_remote_directory remote_chdir # === change_remote_directory
92
+ alias cd_into_this_remote_directory remote_chdir # === cd_into_this_remote_directory
93
+ alias remote_change_directory remote_chdir # === remote_change_directory
94
+
95
+ # ========================================================================= #
96
+ # === return_remote_directories
97
+ #
98
+ # Give us a list of (remote) directories - only directories, not
99
+ # files.
100
+ #
101
+ # An Array will be returned as a result.
102
+ # ========================================================================= #
103
+ def return_remote_directories
104
+ _ = []
105
+ update_file_listing # Populate the file listing anew, so we will always get proper results back.
106
+ raw_listing?.each {|entry|
107
+ entry = FtpParadise::Entry.new(entry)
108
+ _ << rds(entry.return_name) if entry.is_a_directory?
109
+ }
110
+ # ======================================================================= #
111
+ # Directories must end with '/'. Ensure this to be the case next.
112
+ # ======================================================================= #
113
+ _.map! {|entry|
114
+ entry << '/' unless entry.end_with? '/'
115
+ entry
116
+ }
117
+ return _
118
+ end; alias directories? return_remote_directories # === directories?
119
+ alias return_directories return_remote_directories # === return_directories
120
+
121
+ # ========================================================================= #
122
+ # === return_remote_directory_content
123
+ #
124
+ # This method will return ALL remote entries, no matter if file or
125
+ # directory.
126
+ # ========================================================================= #
127
+ def return_remote_directory_content
128
+ raw_entries = raw_entries?
129
+ if raw_entries.nil?
130
+ populate_raw_entries
131
+ raw_entries = raw_entries?
132
+ end
133
+ if raw_entries
134
+ _ = raw_entries.reject {|line|
135
+ line.empty?
136
+ }.map {|entry|
137
+ FtpParadise::Entry.new(entry).name?
138
+ }
139
+ end
140
+ return _
141
+ end; alias array_file_listing? return_remote_directory_content # === array_file_listing?
142
+ alias array_file_listing return_remote_directory_content # === array_file_listing
143
+ alias remote_directory_content return_remote_directory_content # === remote_directory_content
144
+ alias list? return_remote_directory_content # === list?
145
+
146
+ # ========================================================================= #
147
+ # === is_a_directory?
148
+ #
149
+ # This method queries whether the given input is a (remote) directory.
150
+ # For this to work, the given input must obviously exist as file or
151
+ # directory.
152
+ # ========================================================================= #
153
+ def is_a_directory?(i)
154
+ update_file_listing
155
+ candidates = file_listing_as_entries?.select {|entry|
156
+ entry.is_a_directory?
157
+ }.map(&:last)
158
+ candidates.include? i
159
+ end; alias is_directory? is_a_directory? # === is_directory?
160
+ alias is_a_directory? is_a_directory? # === is_a_directory?
161
+ alias this_remote_directory_exists? is_a_directory? # === this_remote_directory_exists?
162
+ alias is_dir? is_a_directory? # === is_dir?
163
+
164
+ # ========================================================================= #
165
+ # === remote_directory_is_empty?
166
+ #
167
+ # This method will return a Boolean - true if the remote directory
168
+ # is empty, and false otherwise.
169
+ # ========================================================================= #
170
+ def remote_directory_is_empty?
171
+ _ = return_remote_directory_content
172
+ _.reject! {|entry|
173
+ (entry == '.') or (entry == '..')
174
+ }
175
+ _.empty?
176
+ end
177
+
178
+ # ========================================================================= #
179
+ # === create_this_remote_directory (mkdir tag)
180
+ #
181
+ # This method will attempt to create a remote directory.
182
+ #
183
+ # A Net::FTPPermError may result if the permission does not allow for
184
+ # that action.
185
+ # ========================================================================= #
186
+ def create_this_remote_directory(
187
+ i, be_verbose = be_verbose?
188
+ )
189
+ if i.is_a? Array
190
+ i.each {|entry| create_this_remote_directory(entry, be_verbose) }
191
+ else
192
+ i = rds(i+'/')
193
+ if be_verbose
194
+ notify_the_user_about(i, __method__)
195
+ if is_directory?(i)
196
+ opnn; e swarn('Warning - the remote directory ')+
197
+ sdir(i)+swarn(' already exists.')
198
+ opnn; e swarn('We thus can not create a new directory.')
199
+ end
200
+ end
201
+ begin
202
+ ftp_object?.mkdir(i)
203
+ rescue Net::FTPConnectionError
204
+ opnn; e 'Not connected - is the network down/available?'
205
+ rescue Net::FTPPermError
206
+ opnn; e "Net::FTPPermError: Can not create the remote "\
207
+ "directory `#{remote_path?}#{sdir(i)}`"
208
+ opnn; e 'as it - or a file with the same name - already exists.'
209
+ end
210
+ end
211
+ end; alias mkdir create_this_remote_directory # === mkdir
212
+ alias rmkdir create_this_remote_directory # === rmkdir
213
+ alias remote_mkdir create_this_remote_directory # === remote_mkdir
214
+ alias create_directory create_this_remote_directory # === create_directory
215
+ alias create_these_remote_directories create_this_remote_directory # === create_these_remote_directories
216
+ alias remote_create_directory create_this_remote_directory # === remote_create_directory
217
+ alias create_remote_directory create_this_remote_directory # === create_remote_directory
218
+
219
+ # ========================================================================= #
220
+ # === sanitize_remote_directory_content
221
+ #
222
+ # The purpose of this method is to clean up the remote dataset.
223
+ #
224
+ # Keep in mind that the output comes in something like:
225
+ #
226
+ # "-rw-rw-rw- 1 web netscape 6820 May 30 2011 AppendToCookbook.rb"
227
+ # "drwxrwxrwx 2 web netscape 8192 Oct 29 2007 CSS"
228
+ # "-rw-rw-rw- 1 web netscape 10548 May 30 2011 Chained.rb"
229
+ # "-rw-r--r-- 1 330 330 237904 Jun 9 14:24 11.03.2003_UniWien_Biologie_EinfuehrungInDieMikrobiologie.jpg",
230
+ #
231
+ # This should contain all the information that is needed.
232
+ # ========================================================================= #
233
+ def sanitize_remote_directory_content
234
+ _ = []
235
+ raw_entries?.each { |e|
236
+ next if e.empty?
237
+ entry = FtpParadise::Entry.new(e)
238
+ filesize = entry.filesize?
239
+ timestamp = entry.parsed_timestamp?
240
+ # ===================================================================== #
241
+ # === Exclude 3 entries next
242
+ # ===================================================================== #
243
+ next if e.include? 'total' or
244
+ entry.name? == '.' or
245
+ entry.name? == '..' # Batch next.
246
+ # ===================================================================== #
247
+ # === Build up the final Array
248
+ #
249
+ # Our Array will have four entries:
250
+ #
251
+ # (1) Filename
252
+ # (2) File or Directory (String)
253
+ # (3) Filesize
254
+ # (4) Timestamp
255
+ #
256
+ # ===================================================================== #
257
+ _ << [ rds(entry.filename?), entry.file_or_directory, filesize, timestamp ]
258
+ }
259
+ @internal_hash[:sanitized_remote_directory_content] = _ #.compact
260
+ end
261
+
262
+ # ========================================================================= #
263
+ # === sanitized_remote_directory_content?
264
+ # ========================================================================= #
265
+ def sanitized_remote_directory_content?
266
+ update_remote_file_listing
267
+ sanitize_remote_directory_content
268
+ @internal_hash[:sanitized_remote_directory_content]
269
+ end
270
+
271
+ end; end
@@ -0,0 +1,108 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'ftp_paradise/connection/do_login.rb'
6
+ # =========================================================================== #
7
+ module FtpParadise
8
+
9
+ class Connection
10
+
11
+ require 'ftp_paradise/toplevel_methods/remote_url.rb'
12
+
13
+ require 'ftp_paradise/connection/initialize_a_new_net_ftp_object_with_this_url.rb'
14
+ require 'ftp_paradise/connection/is_connected.rb'
15
+ require 'ftp_paradise/connection/password.rb'
16
+ require 'ftp_paradise/connection/sync_ftp_object_onto_the_main_namespace.rb'
17
+
18
+ # ========================================================================= #
19
+ # === do_login
20
+ #
21
+ # This method is responsible for the login-action.
22
+ #
23
+ # The method signature for the net-ftp class' .login() is:
24
+ #
25
+ # login(user = "anonymous", passwd = nil, acct = nil)
26
+ #
27
+ # This method here accepts a Hash as first argument.
28
+ #
29
+ # For official information about .login(), see here:
30
+ #
31
+ # https://ruby-doc.org/stdlib/libdoc/net/ftp/rdoc/Net/FTP.html#method-i-login
32
+ #
33
+ # ========================================================================= #
34
+ def do_login(
35
+ to_this_url = nil, # The remote URL.
36
+ use_this_as_username = username?, # The login-name.
37
+ use_this_as_password = password?, # The password for that user.
38
+ be_verbose = be_verbose?
39
+ )
40
+ if to_this_url.nil?
41
+ to_this_url = FtpParadise.remote_url?
42
+ elsif to_this_url.is_a? Hash
43
+ end
44
+ # ======================================================================= #
45
+ # Rescue nil-passwords here.
46
+ # ======================================================================= #
47
+ if use_this_as_password.to_s.empty?
48
+ use_this_as_password = set_password(:try_to_use_a_default_password)
49
+ end
50
+ if be_verbose
51
+ # ===================================================================== #
52
+ # Display some info to the user here.
53
+ # ===================================================================== #
54
+ e; cliner
55
+ opnn; e "Using the URL #{royalblue(to_this_url)} (remote FTP host)."
56
+ e
57
+ e " Username: #{slateblue(use_this_as_username)}"
58
+ e " Password: #{slateblue(use_this_as_password)}"
59
+ e
60
+ report_transfer_mode_in_use
61
+ e
62
+ cliner
63
+ end
64
+ if ftp_object?.nil? and !to_this_url.nil?
65
+ initialize_a_new_net_ftp_object_with_this_url(to_this_url)
66
+ end
67
+ use_this_as_username = use_this_as_username.to_s
68
+ # ======================================================================= #
69
+ # The following code must be rescued because the login() method
70
+ # may fail in various ways.
71
+ # ======================================================================= #
72
+ begin
73
+ ftp_object?.login(
74
+ use_this_as_username,
75
+ use_this_as_password
76
+ )
77
+ # =================================================================== #
78
+ # Next, assign towards the toplevel reference to the ftp-connection.
79
+ # =================================================================== #
80
+ sync_ftp_object_onto_the_main_namespace if ftp_object?
81
+ if be_verbose and is_connected?
82
+ e
83
+ cliner {
84
+ e "- #{sfancy('Successfully')} logged into "\
85
+ "the remote FTP host at `#{simp(to_this_url)}`"
86
+ }
87
+ end
88
+ rescue Net::FTPPermError => error
89
+ opnn; e "We could not connect and login to `#{sfancy(to_this_url)}`."
90
+ opnn; e 'It may be that you lack the proper permissions.'
91
+ opnn; e 'This may happen because the user/password combination was'
92
+ opnn; e 'incorrect. User and password combination will be shown next:'
93
+ show_user_and_password
94
+ opnn; e "Feedbacking that error next, of class #{error.class.to_s}:"
95
+ opnn; e orange(error.to_s)
96
+ rescue Net::FTPConnectionError => error
97
+ opnn; e 'We do not seem to be connected. An error happened.'
98
+ pp error
99
+ pp error.class
100
+ end
101
+ end; alias do_connect do_login # === do_connect
102
+ alias connect_to do_login # === connect_to
103
+ alias connect do_login # === connect
104
+ alias login do_login # === login
105
+ alias login_to do_login # === login_to
106
+ alias reconnect do_login # === reconnect
107
+
108
+ end; end
@@ -0,0 +1,86 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'ftp_paradise/connection/download.rb'
6
+ # =========================================================================== #
7
+ module FtpParadise
8
+
9
+ class Connection
10
+
11
+ # ========================================================================= #
12
+ # === download_binary_file
13
+ #
14
+ # Use this method to download a binary file, by calling the method
15
+ # getbinaryfile(). You can download as many files as you want to
16
+ # through this method, but we expect this method to be a binary
17
+ # file.
18
+ #
19
+ # Specific usage example:
20
+ #
21
+ # ftp?.download_binary_file('photos_2009-03-29.zip', 'ftp_photos/photos.zip')
22
+ #
23
+ # ========================================================================= #
24
+ def download_binary_file(
25
+ i,
26
+ be_verbose = be_verbose?
27
+ )
28
+ if i.is_a? Array
29
+ i.each {|entry| download_binary_file(entry) }
30
+ else
31
+ ftp?.getbinaryfile(i) # Delegate towards .getbinaryfile()
32
+ if be_verbose
33
+ e "Downloaded file #{sfile(i)}."
34
+ end
35
+ end
36
+ end; alias getbinaryfile download_binary_file # === getbinaryfile
37
+
38
+ # ========================================================================= #
39
+ # === download_remote_file (download tag)
40
+ #
41
+ # Use this method to download a remote file. If you are sure to have
42
+ # a binary file, the method download_binary_file() could be used
43
+ # instead.
44
+ #
45
+ # gettextfile(remotefile, localfile = File.basename(remotefile)) {|line| ...}
46
+ # ========================================================================= #
47
+ def download_remote_file(
48
+ i, be_verbose = be_verbose?
49
+ )
50
+ if i.is_a? Array # Handle arrays first.
51
+ i.each {|entry| download_remote_file(entry, be_verbose) }
52
+ else
53
+ if i =~ /^\d+$/ # if is a number
54
+ update_file_listing
55
+ i = return_remote_files[i.to_i - 1].first
56
+ end
57
+ if i == '*' # Here we want to download all files, as we passed in '*'.
58
+ i = []
59
+ update_file_listing
60
+ return_remote_files.each { |a,b| i << FtpParadise.rds(a) }
61
+ end
62
+ if be_verbose
63
+ notify_the_user_about(i, __method__)
64
+ end
65
+ set_file(i) # This assigns to @internal_hash[:file].
66
+ begin # We can use @file because we called set_file() before.
67
+ ftp_object?.gettextfile(file?)
68
+ basename = File.basename(file?)
69
+ e "Finished downloading `#{sandybrown(file?)}`"
70
+ e 'into `'+sdir(rds(Dir.pwd+'/'+basename))+'`.'
71
+ return file?
72
+ rescue Net::FTPPermError => error
73
+ pp error
74
+ e 'An exception occurred in the method '+sfancy('download()')+'.'
75
+ e 'The error was a '+sfancy('Permission Error')+', the input '\
76
+ 'to the method was: `'+simp(i)+'`.'
77
+ e 'Is the file that you are trying to download really '\
78
+ 'existing on the remote server?'
79
+ return false
80
+ end
81
+ end
82
+ end; alias download download_remote_file # === download
83
+ alias download_this_remote_file download_remote_file # === download_this_remote_file
84
+ alias download_this_file download_remote_file # === download_this_file
85
+
86
+ end; end