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,13 @@
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
+ # Next, ftp_paradise-specific .rb files:
12
+ # =========================================================================== #
13
+ 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/gtk/ftp_binding.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,29 @@
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
+ require 'ftp_paradise/connection/connection.rb'
10
+
11
+ # ========================================================================= #
12
+ # === FtpParadise.can_connect_to_remote_site?
13
+ #
14
+ # This method can be used to query whether we can connect to a remote
15
+ # website via the FtpParadise project.
16
+ #
17
+ # The method will return a boolean: either true or false.
18
+ # ========================================================================= #
19
+ def self.can_connect_to_remote_site?
20
+ ftp = FtpParadise::Connection.new(:dont_run_yet) { :use_default_dataset }
21
+ ftp.be_quiet
22
+ return ftp.is_connected?
23
+ end
24
+
25
+ end
26
+
27
+ if __FILE__ == $PROGRAM_NAME
28
+ p FtpParadise.can_connect_to_remote_site?
29
+ 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,49 @@
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
+ require 'ftp_paradise/connection/connection.rb'
10
+
11
+ # ========================================================================= #
12
+ # === FtpParadise.connect
13
+ #
14
+ # To use this convenient connection-method, do this:
15
+ #
16
+ # _ = FtpParadise.connect to: :shevy
17
+ # ========================================================================= #
18
+ def self.connect(
19
+ where_to = {}
20
+ )
21
+ if where_to.is_a? Hash
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
+ FtpParadise::Connection.new(
45
+ remote_host, run_already, &block
46
+ )
47
+ end; self.instance_eval { alias open new } # === FtpParadosie.open
48
+
49
+ end
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ module FtpParadise
6
+
7
+ require 'fileutils'
8
+
9
+ # ========================================================================= #
10
+ # === FtpParadise.create_file
11
+ #
12
+ # Create a local file, via .touch().
13
+ # ========================================================================= #
14
+ def self.create_file(i)
15
+ FileUtils.touch(i)
16
+ end; self.instance_eval { alias touch create_file } # === FtpParadise.touch
17
+
18
+ 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,23 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ module FtpParadise
6
+
7
+ require 'fileutils'
8
+
9
+ # ========================================================================= #
10
+ # === FtpParadise.delete (del tag)
11
+ #
12
+ # Consistently use this method if you wish to delete a (local) file.
13
+ # ========================================================================= #
14
+ def self.delete(i) # ← Added this method as of Apr 2014.
15
+ i = i.to_s # We don't want nil-errors here.
16
+ if File.exist? i
17
+ File.delete(i)
18
+ else
19
+ e "No file at #{sfile(i)} appears to exist."
20
+ end
21
+ end; self.instance_eval { alias remove delete } # === FtpParadise.remove
22
+
23
+ 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,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,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)['bytehost']['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