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,174 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'ftp_paradise/connection/file_handling.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module FtpParadise
|
8
|
+
|
9
|
+
class Connection
|
10
|
+
|
11
|
+
# ========================================================================= #
|
12
|
+
# === create_remote_file (touch tag)
|
13
|
+
#
|
14
|
+
# This "touches" a remote file.
|
15
|
+
# ========================================================================= #
|
16
|
+
def create_remote_file(
|
17
|
+
i,
|
18
|
+
be_verbose = be_verbose?
|
19
|
+
)
|
20
|
+
if i.is_a? Array
|
21
|
+
i.each {|entry| create_remote_file(entry, be_verbose) }
|
22
|
+
else
|
23
|
+
FileUtils.touch(i)
|
24
|
+
if be_verbose
|
25
|
+
notify_the_user_about(i, __method__)
|
26
|
+
end
|
27
|
+
upload_this_text_file(i, :be_quiet)
|
28
|
+
File.delete(i) if File.zero? i # And get rid of that file too.
|
29
|
+
end
|
30
|
+
end; alias touch create_remote_file # === touch
|
31
|
+
|
32
|
+
# ========================================================================= #
|
33
|
+
# === fancy_remote_listing
|
34
|
+
#
|
35
|
+
# This method will obtain the (remote) directory listing and then
|
36
|
+
# display it.
|
37
|
+
# ========================================================================= #
|
38
|
+
def fancy_remote_listing(
|
39
|
+
be_verbose = be_verbose?
|
40
|
+
)
|
41
|
+
update_file_listing
|
42
|
+
case be_verbose
|
43
|
+
when :be_silent,
|
44
|
+
:be_quiet
|
45
|
+
be_verbose = false
|
46
|
+
when :also_show_filesize
|
47
|
+
be_verbose = true
|
48
|
+
end
|
49
|
+
if be_verbose
|
50
|
+
e ('=' * 55)+' '+
|
51
|
+
FtpParadise.yellow('REMOTE FILES')+' '+('=' * 12)
|
52
|
+
if remote_directory_is_empty?
|
53
|
+
e "Remote `#{sdir(remote_path?)}` is empty."
|
54
|
+
e 'No files or directories can be found therein.'
|
55
|
+
else
|
56
|
+
e 'Remote content of `'+sdir(remote_path?)+'` is:'+N+N
|
57
|
+
e 'Index Filename '\
|
58
|
+
' Filesize'
|
59
|
+
show_remote_file_listing
|
60
|
+
end
|
61
|
+
cliner
|
62
|
+
end
|
63
|
+
return remote_directory_content
|
64
|
+
end
|
65
|
+
|
66
|
+
# ========================================================================= #
|
67
|
+
# === rename
|
68
|
+
#
|
69
|
+
# This method will attempt to rename a file on the remote server.
|
70
|
+
#
|
71
|
+
# Note that this is equivalent to moving a file, which is why the alias
|
72
|
+
# move_file can also be used. Any move-file actioni s simply a rename()
|
73
|
+
# action.
|
74
|
+
#
|
75
|
+
# The first argument passed to this method should be the name of an
|
76
|
+
# existing (remote) file. The second second argument should be the
|
77
|
+
# new name of that file, or its full (remote) path.
|
78
|
+
#
|
79
|
+
# Also note that it seems as if the FTP protocol requires the full
|
80
|
+
# target location, otherwise errors such as the following might
|
81
|
+
# happen:
|
82
|
+
#
|
83
|
+
# ftp.rb in `getresp': 451 Rename/move failure: Is a directory (Net::FTPTempError)
|
84
|
+
#
|
85
|
+
# The command used by .rename() command should be equivalent to this code:
|
86
|
+
#
|
87
|
+
# SITE mv oldpath newpath
|
88
|
+
#
|
89
|
+
# Documentation for the functionality can be found here:
|
90
|
+
#
|
91
|
+
# http://ruby-doc.org/stdlib/libdoc/net/ftp/rdoc/Net/FTP.html#method-i-rename
|
92
|
+
#
|
93
|
+
# ========================================================================= #
|
94
|
+
def rename(
|
95
|
+
from,
|
96
|
+
to,
|
97
|
+
be_verbose = be_verbose?
|
98
|
+
)
|
99
|
+
to = to.first if to.is_a? Array
|
100
|
+
if from.is_a? Array # Support batch-transfer.
|
101
|
+
from.each {|entry| rename(entry, to) }
|
102
|
+
else
|
103
|
+
from = rds(from)
|
104
|
+
to = rds(to)
|
105
|
+
begin
|
106
|
+
ftp_object?.rename(from, to)
|
107
|
+
if be_verbose
|
108
|
+
opnn; e "Renamed the remote entry `#{sfancy(from)}"\
|
109
|
+
"` to `#{sfancy(to)}`."
|
110
|
+
end
|
111
|
+
rescue Net::FTPTempError => error
|
112
|
+
e "An error (#{simp('Net::FTPTempError')}) occurred "\
|
113
|
+
"in the method #{simp('rename()')}:"
|
114
|
+
pp error
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end; alias rename_file rename # === rename_file
|
118
|
+
alias move_file rename # === move_file
|
119
|
+
alias rename_remote_file rename # === rename_remote_file
|
120
|
+
|
121
|
+
# ========================================================================= #
|
122
|
+
# === update_remote_file_listing
|
123
|
+
# ========================================================================= #
|
124
|
+
def update_remote_file_listing(
|
125
|
+
be_verbose = be_verbose?
|
126
|
+
)
|
127
|
+
case be_verbose
|
128
|
+
when :be_quiet
|
129
|
+
be_verbose = false
|
130
|
+
end
|
131
|
+
if is_connected?
|
132
|
+
begin
|
133
|
+
# =================================================================== #
|
134
|
+
# Make use of a method that will skip a few entries, such as
|
135
|
+
# "." or "..".
|
136
|
+
# =================================================================== #
|
137
|
+
@internal_hash[:raw_entries] = return_slightly_sanitized_entries_ignoring_a_few
|
138
|
+
rescue Exception => error
|
139
|
+
opnn; e swarn('An error happened in the method '\
|
140
|
+
'update_remote_file_listing(), at '\
|
141
|
+
'line: '+__LINE__.to_s+'.')
|
142
|
+
pp error.class
|
143
|
+
pp error
|
144
|
+
end
|
145
|
+
else
|
146
|
+
if be_verbose
|
147
|
+
opnn; e 'Can not update the remote file listing '\
|
148
|
+
'because we are not connected.'
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end; alias update_file_listing update_remote_file_listing # === update_file_listing
|
152
|
+
alias update_raw_listing update_remote_file_listing # === update_raw_listing
|
153
|
+
alias get_listing update_remote_file_listing # === get_listing
|
154
|
+
alias get_remote_listing update_remote_file_listing # === get_remote_listing
|
155
|
+
alias update update_remote_file_listing # === update
|
156
|
+
|
157
|
+
# ========================================================================= #
|
158
|
+
# === does_this_remote_file_exist?
|
159
|
+
# ========================================================================= #
|
160
|
+
def does_this_remote_file_exist?(i)
|
161
|
+
i = File.basename(i).strip
|
162
|
+
array = return_all_remote_files
|
163
|
+
if array.is_a?(Array) and
|
164
|
+
array.first.is_a?(String)
|
165
|
+
array.map! {|entry|
|
166
|
+
entry = FtpParadise::Entry.new(entry)
|
167
|
+
}
|
168
|
+
array.select! {|entry| entry.is_a_file? }
|
169
|
+
array.map! {|entry| entry.filename? }
|
170
|
+
end
|
171
|
+
return array.include?(i)
|
172
|
+
end
|
173
|
+
|
174
|
+
end; end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'ftp_paradise/connection/ftp_object.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module FtpParadise
|
8
|
+
|
9
|
+
class Connection
|
10
|
+
|
11
|
+
# ========================================================================= #
|
12
|
+
# === ftp_object?
|
13
|
+
# ========================================================================= #
|
14
|
+
def ftp_object?
|
15
|
+
@ftp_object
|
16
|
+
end; alias net_ftp? ftp_object? # === net_ftp?
|
17
|
+
alias ftp? ftp_object? # === ftp?
|
18
|
+
alias ftp ftp_object? # === ftp?
|
19
|
+
alias ftp_object ftp_object? # === ftp_object
|
20
|
+
|
21
|
+
end; end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'ftp_paradise/connection/initialize.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module FtpParadise
|
8
|
+
|
9
|
+
class Connection
|
10
|
+
|
11
|
+
require 'ftp_paradise/base/prototype.rb'
|
12
|
+
include ::FtpParadise::Base
|
13
|
+
|
14
|
+
require 'ftp_paradise/connection/constants.rb' # ← For the constant RUN_ALREADY
|
15
|
+
require 'ftp_paradise/connection/ftp_object.rb'
|
16
|
+
require 'ftp_paradise/connection/reset.rb'
|
17
|
+
require 'ftp_paradise/connection/run.rb'
|
18
|
+
require 'ftp_paradise/connection/set_input.rb'
|
19
|
+
require 'ftp_paradise/connection/remote_url.rb'
|
20
|
+
require 'ftp_paradise/connection/use_default_dataset.rb'
|
21
|
+
|
22
|
+
# ========================================================================= #
|
23
|
+
# === initialize
|
24
|
+
#
|
25
|
+
# The first argument to this method should be the remote host's URL.
|
26
|
+
# ========================================================================= #
|
27
|
+
def initialize(
|
28
|
+
i = ARGV,
|
29
|
+
run_already = RUN_ALREADY
|
30
|
+
)
|
31
|
+
reset
|
32
|
+
# ======================================================================= #
|
33
|
+
# - If we pass in a Hash as the first argument, then we will use
|
34
|
+
# set_data(), otherwise we will set individually it all individually.
|
35
|
+
# ======================================================================= #
|
36
|
+
if i.is_a? Hash
|
37
|
+
set_data(i)
|
38
|
+
else
|
39
|
+
set_input(i)
|
40
|
+
end
|
41
|
+
case i
|
42
|
+
when :dont_run_yet,
|
43
|
+
:do_not_run_yet
|
44
|
+
run_already = false
|
45
|
+
end
|
46
|
+
case run_already
|
47
|
+
when :dont_run_yet
|
48
|
+
run_already = false
|
49
|
+
end
|
50
|
+
if run_already.is_a? Hash
|
51
|
+
_ = run_already
|
52
|
+
if _.has_key? :connect_to_this_host
|
53
|
+
set_this_host(
|
54
|
+
_.delete(:connect_to_this_host)
|
55
|
+
)
|
56
|
+
end
|
57
|
+
run_already = RUN_ALREADY # Restore to the default in this case.
|
58
|
+
end
|
59
|
+
if block_given?
|
60
|
+
yielded = yield
|
61
|
+
case yielded
|
62
|
+
# ===================================================================== #
|
63
|
+
# === :do_not_run_yet
|
64
|
+
# ===================================================================== #
|
65
|
+
when :do_not_run_yet
|
66
|
+
run_already = false
|
67
|
+
# ===================================================================== #
|
68
|
+
# The "default" dataset defaults to my personal FTP login dataset.
|
69
|
+
# ===================================================================== #
|
70
|
+
when :use_default_dataset,
|
71
|
+
:default_dataset,
|
72
|
+
:default
|
73
|
+
use_default_dataset
|
74
|
+
end
|
75
|
+
end
|
76
|
+
run if run_already
|
77
|
+
end
|
78
|
+
|
79
|
+
# ========================================================================= #
|
80
|
+
# === initialize_a_new_net_ftp_object_with_this_remote_url
|
81
|
+
#
|
82
|
+
# This method is the only one allowed to create a new Net::FTP instance.
|
83
|
+
# ========================================================================= #
|
84
|
+
def initialize_a_new_net_ftp_object_with_this_remote_url(i)
|
85
|
+
@ftp_object = Net::FTP.new(i) # ftp = Net::FTP.new(YAML.load_file(ENV['FTP_YAML_FILE'])['freehosting']['url'])
|
86
|
+
end; alias initialize_a_new_net_ftp_object initialize_a_new_net_ftp_object_with_this_remote_url # === initialize_a_new_net_ftp_object
|
87
|
+
|
88
|
+
end; end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'ftp_paradise/connection/initialize_a_new_net_ftp_object_with_this_url.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module FtpParadise
|
8
|
+
|
9
|
+
class Connection
|
10
|
+
|
11
|
+
require 'net/ftp'
|
12
|
+
|
13
|
+
# ========================================================================= #
|
14
|
+
# === initialize_a_new_net_ftp_object_with_this_url
|
15
|
+
# ========================================================================= #
|
16
|
+
def initialize_a_new_net_ftp_object_with_this_url(this_url)
|
17
|
+
@ftp_object = Net::FTP.new(this_url)
|
18
|
+
end
|
19
|
+
|
20
|
+
end; end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'ftp_paradise/connection/is_connected.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module FtpParadise
|
8
|
+
|
9
|
+
class Connection
|
10
|
+
|
11
|
+
require 'ftp_paradise/connection/ftp_object.rb'
|
12
|
+
|
13
|
+
# ========================================================================= #
|
14
|
+
# === closed?
|
15
|
+
#
|
16
|
+
# Returns true if the connection to our remote host is closed.
|
17
|
+
# ========================================================================= #
|
18
|
+
def closed?
|
19
|
+
begin
|
20
|
+
ftp_object?.closed? if ftp_object?
|
21
|
+
rescue Net::FTPConnectionError
|
22
|
+
true
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# ========================================================================= #
|
27
|
+
# === open?
|
28
|
+
#
|
29
|
+
# This method can also be used to determine whether we are still
|
30
|
+
# connected to the remote site.
|
31
|
+
#
|
32
|
+
# This method will return true if the connection is open.
|
33
|
+
#
|
34
|
+
# If you want to determine whether you are still connected to the
|
35
|
+
# remote host, you can alias use the alias are_we_connected? - it
|
36
|
+
# may read nicer.
|
37
|
+
# ========================================================================= #
|
38
|
+
def open?
|
39
|
+
!closed?
|
40
|
+
end; alias are_we_connected? open? # === are_we_connected?
|
41
|
+
alias is_connected? open? # === is_connected?
|
42
|
+
alias is_connected open? # === is_connected
|
43
|
+
alias connected? open? # === connected?
|
44
|
+
alias did_we_connect? open? # === did_we_connect?
|
45
|
+
|
46
|
+
end; end
|
@@ -0,0 +1,474 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'ftp_paradise/connection/misc.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module FtpParadise
|
8
|
+
|
9
|
+
class Connection
|
10
|
+
|
11
|
+
require 'ftp_paradise/connection/directory_handling.rb'
|
12
|
+
require 'ftp_paradise/connection/download.rb'
|
13
|
+
require 'ftp_paradise/toplevel_methods/clear_user_dataset.rb'
|
14
|
+
|
15
|
+
# ========================================================================= #
|
16
|
+
# === dataset?
|
17
|
+
# ========================================================================= #
|
18
|
+
def dataset?
|
19
|
+
FtpParadise.data?
|
20
|
+
end
|
21
|
+
|
22
|
+
# ========================================================================= #
|
23
|
+
# === raw_list
|
24
|
+
# ========================================================================= #
|
25
|
+
def raw_list(i = '*')
|
26
|
+
ftp_object?.list(i)
|
27
|
+
end
|
28
|
+
|
29
|
+
# ========================================================================= #
|
30
|
+
# === return_slightly_sanitized_entries_ignoring_a_few
|
31
|
+
# ========================================================================= #
|
32
|
+
def return_slightly_sanitized_entries_ignoring_a_few(
|
33
|
+
i = '*'
|
34
|
+
)
|
35
|
+
ftp_object?.list(i).reject {|entry|
|
36
|
+
entry.to_s.strip.empty? or entry.end_with?(' .') or entry.end_with?(' ..')
|
37
|
+
}.map {|line|
|
38
|
+
if line.end_with? ':' # <- Some remote FTP-hosts use ':' for a directory.
|
39
|
+
line[-1,1] = '/'
|
40
|
+
end
|
41
|
+
line
|
42
|
+
}
|
43
|
+
end; alias list return_slightly_sanitized_entries_ignoring_a_few # === list
|
44
|
+
|
45
|
+
# ========================================================================= #
|
46
|
+
# === nlst?
|
47
|
+
#
|
48
|
+
# Returns an array of filenames in the remote directory. This will
|
49
|
+
# yield less information than the "ls -l" variant, aka list().
|
50
|
+
#
|
51
|
+
# Documentation:
|
52
|
+
#
|
53
|
+
# https://ruby-doc.org/stdlib/libdoc/net/ftp/rdoc/Net/FTP.html#method-i-nlst
|
54
|
+
#
|
55
|
+
# ========================================================================= #
|
56
|
+
def nlst?
|
57
|
+
ftp_object?.nlst
|
58
|
+
end; alias nlst nlst? # === nlst
|
59
|
+
|
60
|
+
# ========================================================================= #
|
61
|
+
# === list? (list tag)
|
62
|
+
#
|
63
|
+
# Returns an array of file information in the directory (the output
|
64
|
+
# is like `ls -l`). If a block is given, it iterates through the
|
65
|
+
# listing.
|
66
|
+
# ========================================================================= #
|
67
|
+
def list?(i = '*')
|
68
|
+
# ======================================================================= #
|
69
|
+
# We will also sanitize this a bit.
|
70
|
+
# ======================================================================= #
|
71
|
+
@internal_hash[:raw_entries] = return_slightly_sanitized_entries_ignoring_a_few
|
72
|
+
return @internal_hash[:raw_entries] # And return the result here.
|
73
|
+
end; alias ls list? # === ls
|
74
|
+
alias populate_raw_entries list? # === populate_raw_entries
|
75
|
+
|
76
|
+
# ========================================================================= #
|
77
|
+
# === passive=
|
78
|
+
# ========================================================================= #
|
79
|
+
def passive=(i = true)
|
80
|
+
if ftp_object?
|
81
|
+
ftp_object?.passive = i
|
82
|
+
else
|
83
|
+
e 'No ftp-object has been instantiated yet.'
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
# ========================================================================= #
|
88
|
+
# === list_content (list tag, ls tag)
|
89
|
+
#
|
90
|
+
# List available data.
|
91
|
+
# ========================================================================= #
|
92
|
+
def list_content
|
93
|
+
report_current_remote_dir
|
94
|
+
result = list?
|
95
|
+
cliner { pp result }
|
96
|
+
_ = result.first[0, 1]
|
97
|
+
case _
|
98
|
+
when 'd'
|
99
|
+
e "Directory #{result.first}"
|
100
|
+
# @array_directories
|
101
|
+
when 'l'
|
102
|
+
e "Link #{result.first}"
|
103
|
+
else
|
104
|
+
e "File #{result.first}"
|
105
|
+
end
|
106
|
+
end; alias do_list_content list_content # === list
|
107
|
+
alias listing? list_content # === listing?
|
108
|
+
|
109
|
+
# ========================================================================= #
|
110
|
+
# === file_listing_as_entries?
|
111
|
+
# ========================================================================= #
|
112
|
+
def file_listing_as_entries?
|
113
|
+
_ = remote_file_listing?
|
114
|
+
if _
|
115
|
+
return _.map {|entry| FtpParadise::Entry.new(entry) }
|
116
|
+
end
|
117
|
+
return nil
|
118
|
+
end
|
119
|
+
|
120
|
+
# ========================================================================= #
|
121
|
+
# === empty?
|
122
|
+
# ========================================================================= #
|
123
|
+
def empty?
|
124
|
+
array_remote_files.empty?
|
125
|
+
end
|
126
|
+
|
127
|
+
# ========================================================================= #
|
128
|
+
# === find_matches_for
|
129
|
+
#
|
130
|
+
# This method will return an array of files and directories that match
|
131
|
+
# to the provided input (which we will assume to be a query).
|
132
|
+
# ========================================================================= #
|
133
|
+
def find_matches_for(i)
|
134
|
+
i = i.delete '*'
|
135
|
+
update_file_listing
|
136
|
+
_ = return_remote_directory_content.map(&:first)
|
137
|
+
_ = _.grep(/#{i}/)
|
138
|
+
return _
|
139
|
+
end
|
140
|
+
|
141
|
+
# ========================================================================= #
|
142
|
+
# === output_sorted_by_time
|
143
|
+
#
|
144
|
+
# This method will output the remote content in a time-sorted manner.
|
145
|
+
# ========================================================================= #
|
146
|
+
def output_sorted_by_time
|
147
|
+
_ = sanitized_remote_directory_content?
|
148
|
+
sorted_result = _.sort_by {|array|
|
149
|
+
array.last
|
150
|
+
}.reverse
|
151
|
+
sorted_result.each_with_index {|array, index| index += 1
|
152
|
+
file_or_directory = array[1]
|
153
|
+
name_of_the_file = array.first
|
154
|
+
if file_or_directory == 'directory'
|
155
|
+
name_of_the_file << '/' unless name_of_the_file.end_with? '/'
|
156
|
+
end
|
157
|
+
index = simp( (index.to_s+') ').rjust(6))
|
158
|
+
e index+sfancy(name_of_the_file)
|
159
|
+
}
|
160
|
+
end
|
161
|
+
|
162
|
+
# ========================================================================= #
|
163
|
+
# === last_response
|
164
|
+
#
|
165
|
+
# The server's last response is available through this method here.
|
166
|
+
# ========================================================================= #
|
167
|
+
def last_response
|
168
|
+
ftp_object?.last_response
|
169
|
+
end; alias last_response? last_response # === last_response?
|
170
|
+
alias last_server_response? last_response # === last_server_response?
|
171
|
+
|
172
|
+
# ========================================================================= #
|
173
|
+
# === raw_entries?
|
174
|
+
# ========================================================================= #
|
175
|
+
def raw_entries?
|
176
|
+
@internal_hash[:raw_entries]
|
177
|
+
end; alias remote_file_listing? raw_entries? # === remote_file_listing?
|
178
|
+
alias file_listing? raw_entries? # === file_listing?
|
179
|
+
alias raw_listing? raw_entries? # === raw_listing?
|
180
|
+
|
181
|
+
# ========================================================================= #
|
182
|
+
# === return_all_remote_files
|
183
|
+
#
|
184
|
+
# This method will return an Array with all remote files.
|
185
|
+
# ========================================================================= #
|
186
|
+
def return_all_remote_files
|
187
|
+
results = nil
|
188
|
+
if file_listing?
|
189
|
+
results = file_listing?.select {|entry|
|
190
|
+
if entry.is_a?(String) and !entry.empty?
|
191
|
+
entry = FtpParadise::Entry.new(entry)
|
192
|
+
end
|
193
|
+
entry.is_a_file?
|
194
|
+
}
|
195
|
+
end
|
196
|
+
return results
|
197
|
+
end; alias remote_file_listing? return_all_remote_files # === remote_file_listing?
|
198
|
+
alias all_remote_files? return_all_remote_files # === all_remote_files?
|
199
|
+
alias array_remote_files return_all_remote_files # === array_remote_files
|
200
|
+
alias return_remote_files return_all_remote_files # === return_remote_files
|
201
|
+
alias return_remote_file_listing return_all_remote_files # === return_remote_file_listing
|
202
|
+
alias remote_files? return_all_remote_files # === remote_files
|
203
|
+
alias files? return_all_remote_files # === files?
|
204
|
+
|
205
|
+
# ========================================================================= #
|
206
|
+
# === status?
|
207
|
+
#
|
208
|
+
# Report the status here. This is equivalent to the STAT command.
|
209
|
+
# ========================================================================= #
|
210
|
+
def status?
|
211
|
+
ftp_object?.status.to_s
|
212
|
+
end; alias status status? # === status
|
213
|
+
|
214
|
+
# ========================================================================= #
|
215
|
+
# === return_local_directories
|
216
|
+
#
|
217
|
+
# Return all local directories.
|
218
|
+
# ========================================================================= #
|
219
|
+
def return_local_directories
|
220
|
+
Dir['*'].select {|entry| File.directory?(entry) }
|
221
|
+
end
|
222
|
+
|
223
|
+
# ========================================================================= #
|
224
|
+
# === modification_time_of?
|
225
|
+
#
|
226
|
+
# This method will give us the last modification time of a remote
|
227
|
+
# file, by issuing the mdtm() command.
|
228
|
+
#
|
229
|
+
# The format returned will be in YYYMMDDhhmmss.
|
230
|
+
#
|
231
|
+
# If you require a parsed Time instance, you can use mtime()
|
232
|
+
# on the ftp object.
|
233
|
+
#
|
234
|
+
# Symbols could also be used, such as "pp modification_time_of? :a".
|
235
|
+
# ========================================================================= #
|
236
|
+
def modification_time_of?(i)
|
237
|
+
if i.is_a? Array
|
238
|
+
i.each {|entry| modification_time_of(entry) } # <- Recursive call.
|
239
|
+
else
|
240
|
+
ftp_object?.mdtm(i.to_s)
|
241
|
+
end
|
242
|
+
end; alias mdtm modification_time_of? # === mdtm
|
243
|
+
|
244
|
+
# ========================================================================= #
|
245
|
+
# === set_file
|
246
|
+
#
|
247
|
+
# Use only this to modify the @file variable.
|
248
|
+
# ========================================================================= #
|
249
|
+
def set_file(i = nil)
|
250
|
+
@internal_hash[:file] = i
|
251
|
+
end
|
252
|
+
|
253
|
+
# ========================================================================= #
|
254
|
+
# === is_file?
|
255
|
+
#
|
256
|
+
# This method will check whether the input is a file or not.
|
257
|
+
# It will call the method .is_directory?()
|
258
|
+
# ========================================================================= #
|
259
|
+
def is_file?(i)
|
260
|
+
!is_a_directory?(i)
|
261
|
+
end
|
262
|
+
|
263
|
+
# ========================================================================= #
|
264
|
+
# === logged_in?
|
265
|
+
# ========================================================================= #
|
266
|
+
def logged_in?
|
267
|
+
ftp_object?.instance_variable_get '@logged_in'
|
268
|
+
end
|
269
|
+
|
270
|
+
# ========================================================================= #
|
271
|
+
# === available_hosts?
|
272
|
+
# ========================================================================= #
|
273
|
+
def available_hosts?
|
274
|
+
@internal_hash[:array_available_hosts]
|
275
|
+
end; alias array_available_hosts available_hosts? # === array_available_hosts
|
276
|
+
alias array_available_hosts? available_hosts? # === array_available_hosts?
|
277
|
+
|
278
|
+
# ========================================================================= #
|
279
|
+
# === open_timeout?
|
280
|
+
# ========================================================================= #
|
281
|
+
def open_timeout?
|
282
|
+
ftp_object?.open_timeout.to_s if ftp_object?.respond_to? :open_timeout
|
283
|
+
end
|
284
|
+
|
285
|
+
# ========================================================================= #
|
286
|
+
# === feedback_login_hosts
|
287
|
+
#
|
288
|
+
# Feedback all available login hosts, based on the information stored
|
289
|
+
# in the Array @array_available_hosts.
|
290
|
+
# ========================================================================= #
|
291
|
+
def feedback_login_hosts
|
292
|
+
opnn; e 'The followings hosts are easily available:'
|
293
|
+
e
|
294
|
+
available_hosts?.each { |host| e " - #{sfancy(host)}" }
|
295
|
+
e
|
296
|
+
end
|
297
|
+
|
298
|
+
# ========================================================================= #
|
299
|
+
# === help?
|
300
|
+
# ========================================================================= #
|
301
|
+
def help?
|
302
|
+
ftp_object?.help
|
303
|
+
end; alias help help? # === help
|
304
|
+
|
305
|
+
# ========================================================================= #
|
306
|
+
# === close (close tag)
|
307
|
+
#
|
308
|
+
# Close the connection here.
|
309
|
+
#
|
310
|
+
# Further operations will be impossible until a new connection
|
311
|
+
# is opened up again, via connect().
|
312
|
+
# ========================================================================= #
|
313
|
+
def close
|
314
|
+
ftp_object?.close
|
315
|
+
end
|
316
|
+
|
317
|
+
# ========================================================================= #
|
318
|
+
# === mlsd
|
319
|
+
# ========================================================================= #
|
320
|
+
def mlsd(i)
|
321
|
+
ftp_object?.mlsd(i)
|
322
|
+
end
|
323
|
+
|
324
|
+
# ========================================================================= #
|
325
|
+
# === site
|
326
|
+
# ========================================================================= #
|
327
|
+
def site(i = nil)
|
328
|
+
ftp_object?.site(i)
|
329
|
+
end
|
330
|
+
|
331
|
+
# ========================================================================= #
|
332
|
+
# === file?
|
333
|
+
# ========================================================================= #
|
334
|
+
def file?
|
335
|
+
@internal_hash[:file]
|
336
|
+
end
|
337
|
+
|
338
|
+
# ========================================================================= #
|
339
|
+
# === system_command
|
340
|
+
#
|
341
|
+
# This will return system information from the remote host.
|
342
|
+
#
|
343
|
+
# Stuff like:
|
344
|
+
# UNIX Type: L8
|
345
|
+
# ========================================================================= #
|
346
|
+
def system_command
|
347
|
+
ftp_object?.system
|
348
|
+
end; alias system system_command # === system
|
349
|
+
|
350
|
+
# ========================================================================= #
|
351
|
+
# === report_host_port_user_name_and_password
|
352
|
+
# ========================================================================= #
|
353
|
+
def report_host_port_user_name_and_password
|
354
|
+
ljust = 15
|
355
|
+
e '- Now trying to log in to '+simp(host?)+
|
356
|
+
' (Port: '+swarn(port?)+') using:'
|
357
|
+
e ' '+('Login Name: ').ljust(ljust)+sfancy(user_name?)
|
358
|
+
e ' '+('Password: ').ljust(ljust)+sfancy(password?)
|
359
|
+
end
|
360
|
+
|
361
|
+
# ========================================================================= #
|
362
|
+
# === opnn
|
363
|
+
# ========================================================================= #
|
364
|
+
def opnn
|
365
|
+
super(NAMESPACE)
|
366
|
+
end
|
367
|
+
|
368
|
+
# ========================================================================= #
|
369
|
+
# === read_timeout=
|
370
|
+
#
|
371
|
+
# Setter-method for the #read_timeout attribute.
|
372
|
+
# ========================================================================= #
|
373
|
+
def read_timeout=(i)
|
374
|
+
ftp_object?.read_timeout = i
|
375
|
+
end
|
376
|
+
|
377
|
+
# ========================================================================= #
|
378
|
+
# === size?
|
379
|
+
#
|
380
|
+
# This method will return the size of the given (remote) filename.
|
381
|
+
# ========================================================================= #
|
382
|
+
def size?(i)
|
383
|
+
ftp_object?.size(i)
|
384
|
+
end; alias size size? # === size
|
385
|
+
|
386
|
+
# ========================================================================= #
|
387
|
+
# === padding?
|
388
|
+
# ========================================================================= #
|
389
|
+
def padding?
|
390
|
+
@internal_hash[:padding]
|
391
|
+
end
|
392
|
+
|
393
|
+
# ========================================================================= #
|
394
|
+
# === be_verbose?
|
395
|
+
# ========================================================================= #
|
396
|
+
def be_verbose?
|
397
|
+
@internal_hash[:be_verbose]
|
398
|
+
end
|
399
|
+
|
400
|
+
# ========================================================================= #
|
401
|
+
# === server_welcome_message?
|
402
|
+
#
|
403
|
+
# This method will return the remote server's welcome message.
|
404
|
+
# ========================================================================= #
|
405
|
+
def server_welcome_message?
|
406
|
+
ftp_object?.welcome
|
407
|
+
end; alias welcome? server_welcome_message? # === welcome?
|
408
|
+
alias welcome server_welcome_message? # === welcome
|
409
|
+
|
410
|
+
# ========================================================================= #
|
411
|
+
# === noop
|
412
|
+
# ========================================================================= #
|
413
|
+
def noop
|
414
|
+
ftp_object?.noop
|
415
|
+
end
|
416
|
+
|
417
|
+
# ========================================================================= #
|
418
|
+
# === last_response_code?
|
419
|
+
#
|
420
|
+
# Return the server's last response code.
|
421
|
+
# ========================================================================= #
|
422
|
+
def last_response_code?
|
423
|
+
ftp_object?.last_response_code
|
424
|
+
end; alias last_response_code last_response_code? # === last_response_code
|
425
|
+
|
426
|
+
# ========================================================================= #
|
427
|
+
# === quit (quit tag)
|
428
|
+
#
|
429
|
+
# Use this to quit (and disconnect) from the FTP Connection again.
|
430
|
+
# ========================================================================= #
|
431
|
+
def quit
|
432
|
+
begin
|
433
|
+
if is_connected?
|
434
|
+
if ftp_object?
|
435
|
+
FtpParadise.clear_user_dataset
|
436
|
+
ftp_object?.quit
|
437
|
+
end
|
438
|
+
end
|
439
|
+
rescue Exception => error
|
440
|
+
opnn; e "An error happened in the method #{sfancy(__method__)}()"
|
441
|
+
pp error
|
442
|
+
end
|
443
|
+
end
|
444
|
+
|
445
|
+
# ========================================================================= #
|
446
|
+
# === []
|
447
|
+
# ========================================================================= #
|
448
|
+
def [](i)
|
449
|
+
update_file_listing
|
450
|
+
if i =~ /^\d+$/ # If is a number.
|
451
|
+
i = remote_file_listing.size if i.to_i > remote_file_listing.size
|
452
|
+
i = remote_file_listing[i.to_i - 1].first
|
453
|
+
end
|
454
|
+
return i
|
455
|
+
end
|
456
|
+
|
457
|
+
# ========================================================================= #
|
458
|
+
# === sendcmd
|
459
|
+
#
|
460
|
+
# Sends a command and returns the response of the server.
|
461
|
+
#
|
462
|
+
# This has to be rescued, because there are lots of different errors
|
463
|
+
# possible.
|
464
|
+
# ========================================================================= #
|
465
|
+
def sendcmd(i)
|
466
|
+
begin
|
467
|
+
ftp_object?.sendcmd(i)
|
468
|
+
rescue Exception => error
|
469
|
+
pp error
|
470
|
+
e '(This error may be due to the remote file not existing.)'
|
471
|
+
end
|
472
|
+
end
|
473
|
+
|
474
|
+
end; end
|