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.
- checksums.yaml +7 -0
- data/README.md +319 -0
- data/bin/create_remote_directory +9 -0
- data/bin/ftp_get +17 -0
- data/bin/ftp_gtk3 +7 -0
- data/bin/ftp_upload +42 -0
- data/bin/ftp_upload_binary +18 -0
- data/bin/iftp +7 -0
- data/bin/remote_remove +28 -0
- data/doc/README.gen +302 -0
- data/doc/todo/TODO_FOR_FTP_PARADISE_PROJECT.md +79 -0
- data/ftp_paradise.gemspec +122 -0
- data/lib/ftp_paradise.rb +5 -0
- data/lib/ftp_paradise/base/cliner.rb +23 -0
- data/lib/ftp_paradise/base/colours.rb +83 -0
- data/lib/ftp_paradise/base/prototype.rb +171 -0
- data/lib/ftp_paradise/base/reset.rb +29 -0
- data/lib/ftp_paradise/colours/colours.rb +141 -0
- data/lib/ftp_paradise/colours/use_colours.rb +76 -0
- data/lib/ftp_paradise/configuration/configuration.rb +49 -0
- data/lib/ftp_paradise/connection/README.md +1 -0
- data/lib/ftp_paradise/connection/connection.rb +35 -0
- data/lib/ftp_paradise/connection/constants.rb +46 -0
- data/lib/ftp_paradise/connection/data.rb +164 -0
- data/lib/ftp_paradise/connection/debug.rb +78 -0
- data/lib/ftp_paradise/connection/directory_handling.rb +271 -0
- data/lib/ftp_paradise/connection/do_login.rb +108 -0
- data/lib/ftp_paradise/connection/download.rb +86 -0
- data/lib/ftp_paradise/connection/file_handling.rb +174 -0
- data/lib/ftp_paradise/connection/ftp_object.rb +21 -0
- data/lib/ftp_paradise/connection/initialize.rb +88 -0
- data/lib/ftp_paradise/connection/initialize_a_new_net_ftp_object_with_this_url.rb +20 -0
- data/lib/ftp_paradise/connection/is_connected.rb +46 -0
- data/lib/ftp_paradise/connection/misc.rb +474 -0
- data/lib/ftp_paradise/connection/notify.rb +71 -0
- data/lib/ftp_paradise/connection/password.rb +47 -0
- data/lib/ftp_paradise/connection/port.rb +33 -0
- data/lib/ftp_paradise/connection/remote_pwd.rb +72 -0
- data/lib/ftp_paradise/connection/remote_url.rb +164 -0
- data/lib/ftp_paradise/connection/remove.rb +143 -0
- data/lib/ftp_paradise/connection/reset.rb +78 -0
- data/lib/ftp_paradise/connection/run.rb +18 -0
- data/lib/ftp_paradise/connection/set_array_available_hosts.rb +27 -0
- data/lib/ftp_paradise/connection/set_input.rb +18 -0
- data/lib/ftp_paradise/connection/show.rb +153 -0
- data/lib/ftp_paradise/connection/sync_ftp_object_onto_the_main_namespace.rb +24 -0
- data/lib/ftp_paradise/connection/transfer_mode.rb +163 -0
- data/lib/ftp_paradise/connection/upload.rb +253 -0
- data/lib/ftp_paradise/connection/use_default_dataset.rb +40 -0
- data/lib/ftp_paradise/connection/username.rb +42 -0
- data/lib/ftp_paradise/constants/constants.rb +19 -0
- data/lib/ftp_paradise/constants/misc.rb +57 -0
- data/lib/ftp_paradise/constants/namespace.rb +14 -0
- data/lib/ftp_paradise/constants/newline.rb +14 -0
- data/lib/ftp_paradise/constants/roebe.rb +31 -0
- data/lib/ftp_paradise/constants/roebe_ftp_constants.rb +233 -0
- data/lib/ftp_paradise/entry/entry.rb +300 -0
- data/lib/ftp_paradise/gui/gtk2/ftp_paradise.rb +34 -0
- data/lib/ftp_paradise/gui/gtk3/ftp_paradise.rb +34 -0
- data/lib/ftp_paradise/gui/shared_code/ftp_paradise/ftp_paradise_module.rb +709 -0
- data/lib/ftp_paradise/images/connection_image.png +0 -0
- data/lib/ftp_paradise/interactive_ftp/constants.rb +103 -0
- data/lib/ftp_paradise/interactive_ftp/directory_handling.rb +216 -0
- data/lib/ftp_paradise/interactive_ftp/help.rb +50 -0
- data/lib/ftp_paradise/interactive_ftp/initialize.rb +27 -0
- data/lib/ftp_paradise/interactive_ftp/interactive_ftp.rb +998 -0
- data/lib/ftp_paradise/interactive_ftp/main_loop.rb +51 -0
- data/lib/ftp_paradise/interactive_ftp/menu.rb +786 -0
- data/lib/ftp_paradise/interactive_ftp/misc.rb +208 -0
- data/lib/ftp_paradise/interactive_ftp/mode.rb +124 -0
- data/lib/ftp_paradise/interactive_ftp/readline.rb +113 -0
- data/lib/ftp_paradise/interactive_ftp/remove.rb +97 -0
- data/lib/ftp_paradise/interactive_ftp/reset.rb +90 -0
- data/lib/ftp_paradise/interactive_ftp/run.rb +22 -0
- data/lib/ftp_paradise/interactive_ftp/show.rb +184 -0
- data/lib/ftp_paradise/interactive_ftp/upload.rb +90 -0
- data/lib/ftp_paradise/interactive_ftp/user_input.rb +53 -0
- data/lib/ftp_paradise/project/project.rb +64 -0
- data/lib/ftp_paradise/requires/common_basic_requires.rb +14 -0
- data/lib/ftp_paradise/requires/common_external_requires.rb +9 -0
- data/lib/ftp_paradise/requires/require_the_constants.rb +7 -0
- data/lib/ftp_paradise/requires/require_the_ftp_paradise_project.rb +18 -0
- data/lib/ftp_paradise/requires/require_the_ftp_paradise_project_with_the_GUI_bindings.rb +10 -0
- data/lib/ftp_paradise/requires/require_the_toplevel_methods.rb +24 -0
- data/lib/ftp_paradise/toplevel_methods/can_connect_to_remote_site.rb +28 -0
- data/lib/ftp_paradise/toplevel_methods/clear_user_dataset.rb +28 -0
- data/lib/ftp_paradise/toplevel_methods/connect.rb +50 -0
- data/lib/ftp_paradise/toplevel_methods/data.rb +31 -0
- data/lib/ftp_paradise/toplevel_methods/determine_user_dataset_from_this_hash.rb +37 -0
- data/lib/ftp_paradise/toplevel_methods/directory_related_actions.rb +33 -0
- data/lib/ftp_paradise/toplevel_methods/e.rb +16 -0
- data/lib/ftp_paradise/toplevel_methods/file_related_actions.rb +49 -0
- data/lib/ftp_paradise/toplevel_methods/ftp_object.rb +270 -0
- data/lib/ftp_paradise/toplevel_methods/is_on_roebe.rb +20 -0
- data/lib/ftp_paradise/toplevel_methods/login_name.rb +49 -0
- data/lib/ftp_paradise/toplevel_methods/misc.rb +16 -0
- data/lib/ftp_paradise/toplevel_methods/opn.rb +24 -0
- data/lib/ftp_paradise/toplevel_methods/password.rb +50 -0
- data/lib/ftp_paradise/toplevel_methods/port.rb +41 -0
- data/lib/ftp_paradise/toplevel_methods/rds.rb +18 -0
- data/lib/ftp_paradise/toplevel_methods/remote_url.rb +57 -0
- data/lib/ftp_paradise/toplevel_methods/time.rb +45 -0
- data/lib/ftp_paradise/toplevel_methods/upload_and_download.rb +108 -0
- data/lib/ftp_paradise/version/version.rb +19 -0
- data/lib/ftp_paradise/www/public/css/style.css +3 -0
- data/lib/ftp_paradise/www/sinatra_web_interface.rb +242 -0
- data/lib/ftp_paradise/www/views/index.slim +3 -0
- data/lib/ftp_paradise/www/views/layout.slim +11 -0
- data/lib/ftp_paradise/www/web_interface.cgi +34 -0
- data/lib/ftp_paradise/yaml/automatically_connect_on_startup_of_the_interactive_ftp_shell.yml +1 -0
- data/lib/ftp_paradise/yaml/debug.yml +1 -0
- data/lib/ftp_paradise/yaml/open_in_default_editor.yml +1 -0
- data/lib/ftp_paradise/yaml/show_full_names.yml +1 -0
- data/lib/ftp_paradise/yaml/use_colours.yml +1 -0
- data/test/testing_ftp_paradise.rb +94 -0
- data/test/testing_minimal_pure_net_ftp_example_to_connect.rb +28 -0
- data/test/testing_the_ftp_connection_component.rb +70 -0
- data/test/testing_upload_a_local_directory.rb +10 -0
- metadata +336 -0
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'ftp_paradise/requires/common_basic_requires.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
require 'net/ftp' # Load up the ruby net-ftp library.
|
8
|
+
require 'socket'
|
9
|
+
require 'monitor'
|
10
|
+
|
11
|
+
# =========================================================================== #
|
12
|
+
# Next, ftp_paradise-specific .rb files:
|
13
|
+
# =========================================================================== #
|
14
|
+
require 'ftp_paradise/project/project.rb'
|
@@ -0,0 +1,9 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'ftp_paradise/requires/common_external_requires.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
begin
|
8
|
+
require 'cliner/module'
|
9
|
+
rescue LoadError; end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'ftp_paradise/requires/require_the_constants.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
require 'ftp_paradise/constants/constants.rb'
|
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen-string-literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# This variant will require the ftp_paradise project without the actual
|
6
|
+
# GUI bindings.
|
7
|
+
# =========================================================================== #
|
8
|
+
# require 'ftp_paradise/requires/require_the_ftp_paradise_project.rb'
|
9
|
+
# =========================================================================== #
|
10
|
+
require 'ftp_paradise/project/project.rb'
|
11
|
+
require 'ftp_paradise/requires/require_the_constants.rb'
|
12
|
+
require 'ftp_paradise/requires/common_external_requires.rb'
|
13
|
+
require 'ftp_paradise/requires/common_basic_requires.rb'
|
14
|
+
require 'ftp_paradise/requires/require_the_toplevel_methods.rb'
|
15
|
+
require 'ftp_paradise/entry/entry.rb'
|
16
|
+
require 'ftp_paradise/configuration/configuration.rb'
|
17
|
+
require 'ftp_paradise/connection/initialize.rb'
|
18
|
+
require 'ftp_paradise/interactive_ftp/interactive_ftp.rb'
|
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen-string-literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# This variant will require the ftp_paradise project with the GUI bindings.
|
6
|
+
# =========================================================================== #
|
7
|
+
# require 'ftp_paradise/requires/require_the_ftp_paradise_project_with_the_GUI_bindings.rb'
|
8
|
+
# =========================================================================== #
|
9
|
+
require 'ftp_paradise/requires/require_the_ftp_paradise_project.rb'
|
10
|
+
require 'ftp_paradise/gui/gtk3/ftp_paradise.rb'
|
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'ftp_paradise/requires/require_the_toplevel_methods.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module FtpParadise
|
8
|
+
|
9
|
+
require 'ftp_paradise/project/project.rb'
|
10
|
+
# ========================================================================= #
|
11
|
+
# === FtpParadise.require_the_toplevel_methods
|
12
|
+
# ========================================================================= #
|
13
|
+
def self.require_the_toplevel_methods
|
14
|
+
Dir["#{PROJECT_BASE_DIRECTORY}toplevel_methods/*.rb"].each {|this_file|
|
15
|
+
require this_file
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
# ========================================================================= #
|
20
|
+
# And require these files at once:
|
21
|
+
# ========================================================================= #
|
22
|
+
require_the_toplevel_methods
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'ftp_paradise/toplevel_methods/can_connect_to_remote_site.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module FtpParadise
|
8
|
+
|
9
|
+
# ========================================================================= #
|
10
|
+
# === FtpParadise.can_connect_to_remote_site?
|
11
|
+
#
|
12
|
+
# This method can be used to query whether we can connect to a remote
|
13
|
+
# website via the FtpParadise project.
|
14
|
+
#
|
15
|
+
# The method will return a boolean: either true or false.
|
16
|
+
# ========================================================================= #
|
17
|
+
def self.can_connect_to_remote_site?
|
18
|
+
require 'ftp_paradise/connection/connection.rb'
|
19
|
+
ftp = FtpParadise::Connection.new(:dont_run_yet) { :use_default_dataset }
|
20
|
+
ftp.be_quiet
|
21
|
+
return ftp.is_connected?
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
if __FILE__ == $PROGRAM_NAME
|
27
|
+
p FtpParadise.can_connect_to_remote_site?
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'ftp_paradise/toplevel_methods/clear_user_dataset.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module FtpParadise
|
8
|
+
|
9
|
+
require 'ftp_paradise/toplevel_methods/login_name.rb'
|
10
|
+
require 'ftp_paradise/toplevel_methods/password.rb'
|
11
|
+
require 'ftp_paradise/toplevel_methods/remote_url.rb'
|
12
|
+
|
13
|
+
# ========================================================================= #
|
14
|
+
# === FtpParadise.clear_user_dataset
|
15
|
+
#
|
16
|
+
# This method will reset the user-dataset to nil again, that is,
|
17
|
+
# user name, password and remote url.
|
18
|
+
#
|
19
|
+
# This method had to be added so that we can easily clean-up on
|
20
|
+
# a disconnect-action.
|
21
|
+
# ========================================================================= #
|
22
|
+
def self.clear_user_dataset
|
23
|
+
FtpParadise.set_remote_url(nil)
|
24
|
+
FtpParadise.set_user_name(nil)
|
25
|
+
FtpParadise.set_password(nil)
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'ftp_paradise/toplevel_methods/connect.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module FtpParadise
|
8
|
+
|
9
|
+
# ========================================================================= #
|
10
|
+
# === FtpParadise.connect
|
11
|
+
#
|
12
|
+
# To use this convenient connection-method, do this:
|
13
|
+
#
|
14
|
+
# _ = FtpParadise.connect to: :shevy
|
15
|
+
#
|
16
|
+
# ========================================================================= #
|
17
|
+
def self.connect(
|
18
|
+
where_to = {}
|
19
|
+
)
|
20
|
+
if where_to.is_a? Hash
|
21
|
+
require 'ftp_paradise/connection/connection.rb'
|
22
|
+
FtpParadise::Connection.new(where_to) # This ought to be a Hash anyway.
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# ========================================================================= #
|
27
|
+
# === FtpParadise.new
|
28
|
+
#
|
29
|
+
# Module-method to create a new Connection object.
|
30
|
+
# ========================================================================= #
|
31
|
+
def self.new(
|
32
|
+
remote_host = :default,
|
33
|
+
run_already = FtpParadise::Connection::RUN_ALREADY,
|
34
|
+
&block
|
35
|
+
)
|
36
|
+
case remote_host
|
37
|
+
when :dont_run_yet
|
38
|
+
remote_host = :default
|
39
|
+
run_already = false
|
40
|
+
end
|
41
|
+
if remote_host.is_a? Symbol
|
42
|
+
run_already = remote_host
|
43
|
+
end
|
44
|
+
require 'ftp_paradise/connection/connection.rb'
|
45
|
+
FtpParadise::Connection.new(
|
46
|
+
remote_host, run_already, &block
|
47
|
+
)
|
48
|
+
end; self.instance_eval { alias open new } # === FtpParadosie.open
|
49
|
+
|
50
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'ftp_paradise/toplevel_methods/data.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module FtpParadise
|
8
|
+
|
9
|
+
require 'ftp_paradise/toplevel_methods/login_name.rb'
|
10
|
+
require 'ftp_paradise/toplevel_methods/password.rb'
|
11
|
+
require 'ftp_paradise/toplevel_methods/remote_url.rb'
|
12
|
+
|
13
|
+
# ========================================================================= #
|
14
|
+
# === FtpParadise.data?
|
15
|
+
#
|
16
|
+
# This method will return the name of the user; the password; and the
|
17
|
+
# remote URL. It is mostly just a convenience method.
|
18
|
+
# ========================================================================= #
|
19
|
+
def self.data?
|
20
|
+
{
|
21
|
+
user_name: FtpParadise.username?,
|
22
|
+
password: FtpParadise.password?,
|
23
|
+
remote_url: FtpParadise.remote_url?
|
24
|
+
}
|
25
|
+
end; self.instance_eval { alias dataset? data? } # === FtpParadise.dataset?
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
if __FILE__ == $PROGRAM_NAME
|
30
|
+
pp FtpParadise.data?
|
31
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'ftp_paradise/toplevel_methods/determine_user_dataset_from_this_hash.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module FtpParadise
|
8
|
+
|
9
|
+
require 'ftp_paradise/toplevel_methods/login_name.rb'
|
10
|
+
require 'ftp_paradise/toplevel_methods/remote_url.rb'
|
11
|
+
require 'ftp_paradise/toplevel_methods/password.rb'
|
12
|
+
|
13
|
+
# ========================================================================= #
|
14
|
+
# === FtpParadise.determine_user_dataset_from_this_hash
|
15
|
+
#
|
16
|
+
# This method can set relevant entries from an input Hash.
|
17
|
+
#
|
18
|
+
# The IDs should be 'url', 'user_name' and 'password'.
|
19
|
+
# ========================================================================= #
|
20
|
+
def self.determine_user_dataset_from_this_hash(i)
|
21
|
+
if i.is_a? Hash
|
22
|
+
if i.has_key? 'url'
|
23
|
+
_ = i.fetch('url')
|
24
|
+
FtpParadise.set_remote_url(_)
|
25
|
+
end
|
26
|
+
if i.has_key? 'user_name'
|
27
|
+
_ = i.fetch('user_name')
|
28
|
+
FtpParadise.set_user_name(_)
|
29
|
+
end
|
30
|
+
if i.has_key? 'password'
|
31
|
+
_ = i.fetch('password')
|
32
|
+
FtpParadise.set_password(_)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'ftp_paradise/toplevel_methods/directory_related_actions.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module FtpParadise
|
8
|
+
|
9
|
+
# ========================================================================= #
|
10
|
+
# === FtpParadise.is_directory?
|
11
|
+
#
|
12
|
+
# This will return a boolean - true if the remote target is a directory
|
13
|
+
# and false otherwise.
|
14
|
+
#
|
15
|
+
# By default this method will connect to the :shevy host.
|
16
|
+
# ========================================================================= #
|
17
|
+
def self.is_directory?(
|
18
|
+
i,
|
19
|
+
connect_to_this_host = :shevy
|
20
|
+
)
|
21
|
+
require 'ftp_paradise/connection/connection.rb'
|
22
|
+
FtpParadise::Connection.new(
|
23
|
+
i,
|
24
|
+
connect_to_this_host: connect_to_this_host
|
25
|
+
).is_a_directory?(i)
|
26
|
+
end; self.instance_eval { alias directory? is_directory? } # === FtpParadise.directory?
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
if __FILE__ == $PROGRAM_NAME
|
31
|
+
p FtpParadise.is_directory?('AUSARBEITUNGEN')
|
32
|
+
p FtpParadise.is_directory?('AUSARBEITUNGE')
|
33
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'ftp_paradise/toplevel_methods/e.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module FtpParadise
|
8
|
+
|
9
|
+
# ========================================================================= #
|
10
|
+
# === FtpParadise.e
|
11
|
+
# ========================================================================= #
|
12
|
+
def self.e(i = '')
|
13
|
+
puts i
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'file_related_actions.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module FtpParadise
|
8
|
+
|
9
|
+
require 'fileutils'
|
10
|
+
|
11
|
+
# ========================================================================= #
|
12
|
+
# === FtpParadise.get_files
|
13
|
+
#
|
14
|
+
# Use this method whenever you want to get all (local) files.
|
15
|
+
#
|
16
|
+
# By default, this method will return all files from the current directory.
|
17
|
+
# ========================================================================= #
|
18
|
+
def self.get_files(
|
19
|
+
from = '*'
|
20
|
+
)
|
21
|
+
entries = Dir[from]
|
22
|
+
entries.select! {|entry| File.file?(entry) }
|
23
|
+
entries
|
24
|
+
end
|
25
|
+
|
26
|
+
# ========================================================================= #
|
27
|
+
# === FtpParadise.create_file
|
28
|
+
#
|
29
|
+
# Create a local file, via .touch().
|
30
|
+
# ========================================================================= #
|
31
|
+
def self.create_file(i)
|
32
|
+
FileUtils.touch(i)
|
33
|
+
end; self.instance_eval { alias touch create_file } # === FtpParadise.touch
|
34
|
+
|
35
|
+
# ========================================================================= #
|
36
|
+
# === FtpParadise.delete (del tag)
|
37
|
+
#
|
38
|
+
# Consistently use this method if you wish to delete a (local) file.
|
39
|
+
# ========================================================================= #
|
40
|
+
def self.delete(i) # ← Added this method as of April 2014.
|
41
|
+
i = i.to_s # We don't want nil-errors here.
|
42
|
+
if File.exist? i
|
43
|
+
File.delete(i)
|
44
|
+
else
|
45
|
+
e "No file at #{sfile(i)} appears to exist."
|
46
|
+
end
|
47
|
+
end; self.instance_eval { alias remove delete } # === FtpParadise.remove
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,270 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'ftp_paradise/toplevel_methods/ftp_object.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module FtpParadise
|
8
|
+
|
9
|
+
require 'net/ftp'
|
10
|
+
require 'ftp_paradise/toplevel_methods/e.rb'
|
11
|
+
require 'ftp_paradise/toplevel_methods/login_name.rb'
|
12
|
+
require 'ftp_paradise/toplevel_methods/password.rb'
|
13
|
+
require 'ftp_paradise/toplevel_methods/remote_url.rb'
|
14
|
+
|
15
|
+
# ========================================================================= #
|
16
|
+
# === @ftp_object
|
17
|
+
#
|
18
|
+
# This is the main Net FTP object that we will use to connect to
|
19
|
+
# some remote host. It will be stored on the module-level so that
|
20
|
+
# we can also use module-level methods such as
|
21
|
+
# FtpParadise.ftp_object? for easy access ways.
|
22
|
+
# ========================================================================= #
|
23
|
+
@ftp_object = nil
|
24
|
+
|
25
|
+
require 'yaml'
|
26
|
+
require 'ftp_paradise/constants/roebe.rb'
|
27
|
+
# ========================================================================= #
|
28
|
+
# === FtpParadise.initialize_ftp_object
|
29
|
+
#
|
30
|
+
# Use this method if you wish to initialize a new FTP object. This will
|
31
|
+
# be, by default, a blank-state initializer.
|
32
|
+
# ========================================================================= #
|
33
|
+
def self.initialize_ftp_object(use_this_url = nil)
|
34
|
+
case use_this_url
|
35
|
+
# ======================================================================= #
|
36
|
+
# === :default
|
37
|
+
# ======================================================================= #
|
38
|
+
when :default
|
39
|
+
use_this_url = YAML.load_file(FILE_ROEBE_FTP)['podserver']['url']
|
40
|
+
end
|
41
|
+
@ftp_object = Net::FTP.new(use_this_url)
|
42
|
+
end
|
43
|
+
|
44
|
+
# ========================================================================= #
|
45
|
+
# === FtpParadise.do_login (login tag)
|
46
|
+
#
|
47
|
+
# This method combines setting the remote URL, before doing the login
|
48
|
+
# action.
|
49
|
+
# ========================================================================= #
|
50
|
+
def self.do_login(
|
51
|
+
use_this_as_the_remote_url = nil,
|
52
|
+
user = :default,
|
53
|
+
passwd = :default_or_nil,
|
54
|
+
acct = nil
|
55
|
+
)
|
56
|
+
if use_this_as_the_remote_url and FtpParadise.ftp_object?.nil?
|
57
|
+
FtpParadise.set_remote_url(use_this_as_the_remote_url)
|
58
|
+
end
|
59
|
+
case use_this_as_the_remote_url
|
60
|
+
# ======================================================================= #
|
61
|
+
# === :bytehost
|
62
|
+
# ======================================================================= #
|
63
|
+
when :bytehost
|
64
|
+
FtpParadise.set_remote_url(:infer)
|
65
|
+
use_this_as_the_remote_url = remote_url?
|
66
|
+
end
|
67
|
+
# ======================================================================= #
|
68
|
+
# Sanitize the default user (user name aka login name).
|
69
|
+
# ======================================================================= #
|
70
|
+
case user
|
71
|
+
# ======================================================================= #
|
72
|
+
# === :default
|
73
|
+
# ======================================================================= #
|
74
|
+
when :default
|
75
|
+
if is_on_roebe?
|
76
|
+
set_login_name(:infer)
|
77
|
+
user = login_name?
|
78
|
+
else
|
79
|
+
user = 'anonymous'
|
80
|
+
end
|
81
|
+
end
|
82
|
+
# ======================================================================= #
|
83
|
+
# Sanitize the given password next.
|
84
|
+
# ======================================================================= #
|
85
|
+
case passwd
|
86
|
+
# ======================================================================= #
|
87
|
+
# === :default_or_nil
|
88
|
+
# ======================================================================= #
|
89
|
+
when :default_or_nil
|
90
|
+
if is_on_roebe?
|
91
|
+
set_password(:infer)
|
92
|
+
passwd = password?
|
93
|
+
else
|
94
|
+
passwd = nil
|
95
|
+
end
|
96
|
+
end
|
97
|
+
# ======================================================================= #
|
98
|
+
# puts "Debug: user name is: #{user} password is: #{passwd} account is: #{acct}"
|
99
|
+
# ======================================================================= #
|
100
|
+
@ftp_object.login(
|
101
|
+
user, passwd, acct
|
102
|
+
) # Delegate to the main object here.
|
103
|
+
return @ftp_object # And mandatory return here.
|
104
|
+
end
|
105
|
+
|
106
|
+
# ========================================================================= #
|
107
|
+
# === FtpParadise.use_this_as_ftp_object
|
108
|
+
#
|
109
|
+
# Assignment to a new FTP object can come through this method.
|
110
|
+
# ========================================================================= #
|
111
|
+
def self.use_this_as_ftp_object(i)
|
112
|
+
@ftp_object = i
|
113
|
+
end; self.instance_eval { alias assign_ftp_object= use_this_as_ftp_object } # === FtpParadise.assign_ftp_object=
|
114
|
+
self.instance_eval { alias ftp_object= use_this_as_ftp_object } # === FtpParadise.ftp_object=
|
115
|
+
|
116
|
+
# ========================================================================= #
|
117
|
+
# === FtpParadise.list
|
118
|
+
# ========================================================================= #
|
119
|
+
def self.list(i = 'n*')
|
120
|
+
@ftp_object.list(i)
|
121
|
+
end; self.instance_eval { alias ll list } # === FtpParadise.ll
|
122
|
+
|
123
|
+
# ========================================================================= #
|
124
|
+
# === FtpParadise.close
|
125
|
+
# ========================================================================= #
|
126
|
+
def self.close
|
127
|
+
@ftp_object.close
|
128
|
+
end
|
129
|
+
|
130
|
+
# ========================================================================= #
|
131
|
+
# === FtpParadise.mlsd
|
132
|
+
#
|
133
|
+
# This method will return an Array of the entries of the directory
|
134
|
+
# specified by pathname.
|
135
|
+
#
|
136
|
+
# Each entry has the facts (e.g., size, last modification time, etc.)
|
137
|
+
# and the pathname. If a block is given, it iterates through the listing.
|
138
|
+
#
|
139
|
+
# If pathname is omitted, the current directory is assumed.
|
140
|
+
# ========================================================================= #
|
141
|
+
def self.mlsd(
|
142
|
+
pathname = nil
|
143
|
+
)
|
144
|
+
@ftp_object.mlsd(pathname)
|
145
|
+
end
|
146
|
+
|
147
|
+
# ========================================================================= #
|
148
|
+
# === FtpParadise.delete
|
149
|
+
#
|
150
|
+
# Use this to delete a remote file.
|
151
|
+
# ========================================================================= #
|
152
|
+
def self.delete(i)
|
153
|
+
FtpParadise.ftp_object.delete(i)
|
154
|
+
end; self.instance_eval { alias remove_this_file delete } # === FtpParadise.remove_this_file
|
155
|
+
|
156
|
+
# ========================================================================= #
|
157
|
+
# === FtpParadise.getbinaryfile
|
158
|
+
# ========================================================================= #
|
159
|
+
def self.getbinaryfile(
|
160
|
+
a = 'nif.rb-0.91.gz',
|
161
|
+
b = 'nif.gz',
|
162
|
+
c = 1024
|
163
|
+
)
|
164
|
+
@ftp_object.getbinaryfile(a,b,c)
|
165
|
+
end
|
166
|
+
|
167
|
+
# ========================================================================= #
|
168
|
+
# === FtpParadise.remote_host?
|
169
|
+
# ========================================================================= #
|
170
|
+
def self.remote_host?
|
171
|
+
if @ftp_object
|
172
|
+
@ftp_object.remote_host?
|
173
|
+
else
|
174
|
+
nil
|
175
|
+
end
|
176
|
+
end; self.instance_eval { alias host? remote_host? } # === FtpParadise.host?
|
177
|
+
|
178
|
+
# ========================================================================= #
|
179
|
+
# === FtpParadise.chdir (cd tag)
|
180
|
+
#
|
181
|
+
# Change directory through this method here.
|
182
|
+
#
|
183
|
+
# Usage Example:
|
184
|
+
#
|
185
|
+
# FtpParadise.chdir('pub/lang/ruby/contrib')
|
186
|
+
# FtpParadise.cd('pub/lang/ruby/contrib')
|
187
|
+
#
|
188
|
+
# ========================================================================= #
|
189
|
+
def self.chdir(i)
|
190
|
+
@ftp_object.chdir(i)
|
191
|
+
end; self.instance_eval { alias cd chdir } # === FtpParadise.cd
|
192
|
+
self.instance_eval { alias remote_cd chdir } # === FtpParadise.remote_cd
|
193
|
+
|
194
|
+
# ========================================================================= #
|
195
|
+
# === FtpParadise.ftp_object
|
196
|
+
#
|
197
|
+
# Reader method to return the @ftp_object.
|
198
|
+
#
|
199
|
+
# This method should ideally come last in this .rb file.
|
200
|
+
# ========================================================================= #
|
201
|
+
def self.ftp_object
|
202
|
+
@ftp_object
|
203
|
+
end; self.instance_eval { alias ftp_object? ftp_object } # === FtpParadise.ftp_object?
|
204
|
+
self.instance_eval { alias object ftp_object } # === FtpParadise.object
|
205
|
+
|
206
|
+
# ========================================================================= #
|
207
|
+
# === FtpParadise.show_list
|
208
|
+
#
|
209
|
+
# By default this method will exclude the '.' and '..' entries.
|
210
|
+
# ========================================================================= #
|
211
|
+
def self.show_list
|
212
|
+
result = @ftp_object.list
|
213
|
+
result.each {|line|
|
214
|
+
e line unless line.end_with? '.'
|
215
|
+
}
|
216
|
+
end
|
217
|
+
|
218
|
+
# ========================================================================= #
|
219
|
+
# === FtpParadise.remote_mkdir
|
220
|
+
#
|
221
|
+
# This method will create a remote directory. Make sure to have
|
222
|
+
# a valid (active) FTP connection before you invoke this method.
|
223
|
+
# ========================================================================= #
|
224
|
+
def self.remote_mkdir(
|
225
|
+
create_this_remote_directory,
|
226
|
+
connection = @ftp_object,
|
227
|
+
connect_to_this_host = :shevy
|
228
|
+
)
|
229
|
+
if create_this_remote_directory.is_a? Array
|
230
|
+
create_this_remote_directory.each {|name_of_the_remote_directory|
|
231
|
+
remote_mkdir(
|
232
|
+
name_of_the_remote_directory,
|
233
|
+
connection,
|
234
|
+
connect_to_this_host
|
235
|
+
)
|
236
|
+
}
|
237
|
+
else
|
238
|
+
create_this_remote_directory = create_this_remote_directory.to_s
|
239
|
+
|
240
|
+
if connection.nil?
|
241
|
+
require 'ftp_paradise/connection/connection.rb'
|
242
|
+
connection = FtpParadise::Connection.new(connect_to_this_host) { :do_not_run_yet }
|
243
|
+
connection.be_silent
|
244
|
+
connection.do_login
|
245
|
+
end
|
246
|
+
|
247
|
+
begin
|
248
|
+
connection.mkdir(create_this_remote_directory)
|
249
|
+
rescue Net::FTPPermError => error
|
250
|
+
pp error
|
251
|
+
e "No directory called #{create_this_remote_directory}/ could be created"
|
252
|
+
e 'as such a (remote) directory already exists.'
|
253
|
+
end
|
254
|
+
|
255
|
+
end
|
256
|
+
end; self.instance_eval { alias create_directory remote_mkdir } # === FtpParadise.create_directory
|
257
|
+
self.instance_eval { alias remote_create_directory remote_mkdir } # === FtpParadise.remote_create_directory
|
258
|
+
|
259
|
+
end
|
260
|
+
|
261
|
+
if __FILE__ == $PROGRAM_NAME
|
262
|
+
FtpParadise.initialize_ftp_object(:default)
|
263
|
+
result = FtpParadise.do_login :bytehost
|
264
|
+
pp result.list
|
265
|
+
pp result
|
266
|
+
FtpParadise.cd 'htdocs'
|
267
|
+
FtpParadise.show_list
|
268
|
+
FtpParadise.remote_mkdir('test')
|
269
|
+
FtpParadise.show_list
|
270
|
+
end # ftpobject
|