ronin-support 0.4.1 → 0.5.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog.md +75 -32
- data/Gemfile +17 -18
- data/README.md +9 -10
- data/Rakefile +10 -2
- data/gemspec.yml +1 -1
- data/lib/ronin/binary.rb +21 -0
- data/lib/ronin/binary/hexdump.rb +20 -0
- data/lib/ronin/binary/hexdump/parser.rb +411 -0
- data/lib/ronin/binary/struct.rb +579 -0
- data/lib/ronin/binary/template.rb +437 -0
- data/lib/ronin/extensions/ip_addr.rb +17 -13
- data/lib/ronin/extensions/regexp.rb +45 -0
- data/lib/ronin/extensions/string.rb +3 -3
- data/lib/ronin/formatting/extensions/binary.rb +1 -0
- data/lib/ronin/formatting/extensions/binary/array.rb +63 -0
- data/lib/ronin/formatting/extensions/binary/base64.rb +106 -0
- data/lib/ronin/formatting/extensions/binary/file.rb +39 -6
- data/lib/ronin/formatting/extensions/binary/float.rb +65 -0
- data/lib/ronin/formatting/extensions/binary/integer.rb +56 -43
- data/lib/ronin/formatting/extensions/binary/string.rb +75 -187
- data/lib/ronin/formatting/extensions/text/string.rb +61 -0
- data/lib/ronin/fuzzing/extensions/string.rb +21 -8
- data/lib/ronin/fuzzing/fuzzing.rb +19 -17
- data/lib/ronin/network.rb +2 -1
- data/lib/ronin/network/dns.rb +57 -15
- data/lib/ronin/network/extensions.rb +0 -1
- data/lib/ronin/network/ftp.rb +145 -0
- data/lib/ronin/network/http/http.rb +13 -14
- data/lib/ronin/network/imap.rb +11 -10
- data/lib/ronin/network/mixins.rb +1 -0
- data/lib/ronin/network/mixins/ftp.rb +155 -0
- data/lib/ronin/network/mixins/ssl.rb +1 -1
- data/lib/ronin/network/mixins/tcp.rb +39 -6
- data/lib/ronin/network/mixins/udp.rb +121 -1
- data/lib/ronin/network/mixins/unix.rb +279 -0
- data/lib/ronin/network/pop3.rb +5 -5
- data/lib/ronin/network/proxy.rb +578 -0
- data/lib/ronin/network/smtp/email.rb +1 -1
- data/lib/ronin/network/smtp/smtp.rb +7 -8
- data/lib/ronin/network/ssl.rb +1 -6
- data/lib/ronin/network/tcp.rb +2 -305
- data/lib/ronin/network/tcp/proxy.rb +377 -0
- data/lib/ronin/network/tcp/tcp.rb +435 -0
- data/lib/ronin/network/telnet.rb +27 -23
- data/lib/ronin/network/udp.rb +2 -266
- data/lib/ronin/network/udp/proxy.rb +169 -0
- data/lib/ronin/network/udp/udp.rb +442 -0
- data/lib/ronin/network/unix.rb +287 -0
- data/lib/ronin/path.rb +2 -2
- data/lib/ronin/spec/ui/output.rb +1 -7
- data/lib/ronin/support.rb +1 -0
- data/lib/ronin/support/inflector.rb +3 -7
- data/lib/ronin/support/support.rb +2 -1
- data/lib/ronin/support/version.rb +1 -1
- data/lib/ronin/ui/output/helpers.rb +13 -15
- data/lib/ronin/ui/output/output.rb +2 -2
- data/lib/ronin/ui/output/terminal/color.rb +10 -4
- data/lib/ronin/wordlist.rb +92 -17
- data/ronin-support.gemspec +38 -109
- data/spec/binary/hexdump/helpers/hexdumps.rb +13 -0
- data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/ascii.bin +0 -0
- data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/hexdump_decimal_shorts.txt +0 -0
- data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/hexdump_hex_bytes.txt +0 -0
- data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/hexdump_hex_shorts.txt +0 -0
- data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/hexdump_octal_bytes.txt +0 -0
- data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/hexdump_octal_shorts.txt +0 -0
- data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/hexdump_repeated.txt +0 -0
- data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_decimal_bytes.txt +0 -0
- data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_decimal_ints.txt +0 -0
- data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_decimal_quads.txt +0 -0
- data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_decimal_shorts.txt +0 -0
- data/spec/binary/hexdump/helpers/hexdumps/od_doubles.txt +17 -0
- data/spec/binary/hexdump/helpers/hexdumps/od_floats.txt +17 -0
- data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_hex_bytes.txt +0 -0
- data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_hex_ints.txt +0 -0
- data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_hex_quads.txt +0 -0
- data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_hex_shorts.txt +0 -0
- data/spec/binary/hexdump/helpers/hexdumps/od_named_chars.txt +17 -0
- data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_octal_bytes.txt +0 -0
- data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_octal_ints.txt +0 -0
- data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_octal_quads.txt +0 -0
- data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_octal_shorts.txt +0 -0
- data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_repeated.txt +0 -0
- data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/repeated.bin +0 -0
- data/spec/binary/hexdump/parser_spec.rb +302 -0
- data/spec/binary/struct_spec.rb +496 -0
- data/spec/binary/template_spec.rb +400 -0
- data/spec/extensions/ip_addr_spec.rb +58 -32
- data/spec/extensions/regexp_spec.rb +60 -0
- data/spec/extensions/string_spec.rb +1 -1
- data/spec/formatting/binary/array_spec.rb +22 -0
- data/spec/formatting/binary/base64_spec.rb +50 -0
- data/spec/formatting/binary/float_spec.rb +30 -0
- data/spec/formatting/binary/integer_spec.rb +54 -40
- data/spec/formatting/binary/string_spec.rb +69 -182
- data/spec/formatting/text/string_spec.rb +30 -0
- data/spec/network/dns_spec.rb +64 -0
- data/spec/network/ftp_spec.rb +65 -0
- data/spec/network/proxy_spec.rb +121 -0
- data/spec/network/shared/unix_server.rb +31 -0
- data/spec/network/tcp/proxy_spec.rb +116 -0
- data/spec/network/{tcp_spec.rb → tcp/tcp_spec.rb} +24 -1
- data/spec/network/telnet_spec.rb +67 -0
- data/spec/network/{udp_spec.rb → udp/udp_spec.rb} +24 -1
- data/spec/network/unix_spec.rb +183 -0
- data/spec/wordlist_spec.rb +74 -13
- metadata +129 -85
- data/spec/formatting/binary/helpers/hexdumps.rb +0 -16
@@ -66,6 +66,8 @@ module Ronin
|
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
|
+
module_function
|
70
|
+
|
69
71
|
#
|
70
72
|
# Various bad-strings.
|
71
73
|
#
|
@@ -77,7 +79,7 @@ module Ronin
|
|
77
79
|
# or null-bytes (see {NULL_BYTES}), of varying length
|
78
80
|
# (see {SHORT_LENGTHS} and {LONG_LENGTHS}).
|
79
81
|
#
|
80
|
-
def
|
82
|
+
def bad_strings(&block)
|
81
83
|
yield ''
|
82
84
|
|
83
85
|
chars = [
|
@@ -118,7 +120,7 @@ module Ronin
|
|
118
120
|
# @yieldparam [String] fmt_string
|
119
121
|
# A format-string containing format operators (see {FORMAT_STRINGS}).
|
120
122
|
#
|
121
|
-
def
|
123
|
+
def format_strings(&block)
|
122
124
|
FORMAT_STRINGS.each do |fmt|
|
123
125
|
yield fmt
|
124
126
|
yield fmt * 100
|
@@ -136,7 +138,7 @@ module Ronin
|
|
136
138
|
# @yieldparam [String] path
|
137
139
|
# A known bad path.
|
138
140
|
#
|
139
|
-
def
|
141
|
+
def bad_paths(&block)
|
140
142
|
padding = 'A' * 5_000
|
141
143
|
|
142
144
|
yield "/.:/#{padding}\x00\x00"
|
@@ -166,7 +168,7 @@ module Ronin
|
|
166
168
|
# @yieldparam [String] bitfield
|
167
169
|
# A bit-field (8bit - 64bit).
|
168
170
|
#
|
169
|
-
def
|
171
|
+
def bit_fields(&block)
|
170
172
|
("\x00".."\xff").each do |c|
|
171
173
|
yield c
|
172
174
|
yield c << c # x2
|
@@ -184,7 +186,7 @@ module Ronin
|
|
184
186
|
# @yieldparam [String] bitfield
|
185
187
|
# A signed bit-field (8bit - 64bit).
|
186
188
|
#
|
187
|
-
def
|
189
|
+
def signed_bit_fields(&block)
|
188
190
|
("\x80".."\xff").each do |c|
|
189
191
|
yield c
|
190
192
|
yield c << c # x2
|
@@ -202,7 +204,7 @@ module Ronin
|
|
202
204
|
# @yieldparam [String] int
|
203
205
|
# A unsigned 8bit integer.
|
204
206
|
#
|
205
|
-
def
|
207
|
+
def uint8(&block)
|
206
208
|
("\x00".."\xff").each(&block)
|
207
209
|
end
|
208
210
|
|
@@ -215,7 +217,7 @@ module Ronin
|
|
215
217
|
# @yieldparam [String] int
|
216
218
|
# A unsigned 16bit integer.
|
217
219
|
#
|
218
|
-
def
|
220
|
+
def uint16
|
219
221
|
uint8 { |c| yield c * 2 }
|
220
222
|
end
|
221
223
|
|
@@ -228,7 +230,7 @@ module Ronin
|
|
228
230
|
# @yieldparam [String] int
|
229
231
|
# A unsigned 32bit integer.
|
230
232
|
#
|
231
|
-
def
|
233
|
+
def uint32
|
232
234
|
uint8 { |c| yield c * 4 }
|
233
235
|
end
|
234
236
|
|
@@ -241,7 +243,7 @@ module Ronin
|
|
241
243
|
# @yieldparam [String] int
|
242
244
|
# A unsigned 64bit integer.
|
243
245
|
#
|
244
|
-
def
|
246
|
+
def uint64
|
245
247
|
uint8 { |c| yield c * 8 }
|
246
248
|
end
|
247
249
|
|
@@ -254,7 +256,7 @@ module Ronin
|
|
254
256
|
# @yieldparam [String] int
|
255
257
|
# A signed 8bit integer.
|
256
258
|
#
|
257
|
-
def
|
259
|
+
def int8(&block)
|
258
260
|
("\x00".."\x70").each(&block)
|
259
261
|
end
|
260
262
|
|
@@ -267,7 +269,7 @@ module Ronin
|
|
267
269
|
# @yieldparam [String] int
|
268
270
|
# A signed 16bit integer.
|
269
271
|
#
|
270
|
-
def
|
272
|
+
def int16
|
271
273
|
int8 { |c| yield c * 2 }
|
272
274
|
end
|
273
275
|
|
@@ -280,7 +282,7 @@ module Ronin
|
|
280
282
|
# @yieldparam [String] int
|
281
283
|
# A signed 32bit integer.
|
282
284
|
#
|
283
|
-
def
|
285
|
+
def int32
|
284
286
|
int8 { |c| yield c * 4 }
|
285
287
|
end
|
286
288
|
|
@@ -293,7 +295,7 @@ module Ronin
|
|
293
295
|
# @yieldparam [String] int
|
294
296
|
# A signed 64bit integer.
|
295
297
|
#
|
296
|
-
def
|
298
|
+
def int64
|
297
299
|
int8 { |c| yield c * 8 }
|
298
300
|
end
|
299
301
|
|
@@ -306,7 +308,7 @@ module Ronin
|
|
306
308
|
# @yieldparam [String] int
|
307
309
|
# A negative-signed 8bit integer.
|
308
310
|
#
|
309
|
-
def
|
311
|
+
def sint8(&block)
|
310
312
|
("\x80".."\xff").each(&block)
|
311
313
|
end
|
312
314
|
|
@@ -319,7 +321,7 @@ module Ronin
|
|
319
321
|
# @yieldparam [String] int
|
320
322
|
# A negative-signed 16bit integer.
|
321
323
|
#
|
322
|
-
def
|
324
|
+
def sint16
|
323
325
|
sint8 { |c| yield c * 2 }
|
324
326
|
end
|
325
327
|
|
@@ -332,7 +334,7 @@ module Ronin
|
|
332
334
|
# @yieldparam [String] int
|
333
335
|
# A negative-signed 32bit integer.
|
334
336
|
#
|
335
|
-
def
|
337
|
+
def sint32
|
336
338
|
sint8 { |c| yield c * 4 }
|
337
339
|
end
|
338
340
|
|
@@ -345,7 +347,7 @@ module Ronin
|
|
345
347
|
# @yieldparam [String] int
|
346
348
|
# A negative-signed 64bit integer.
|
347
349
|
#
|
348
|
-
def
|
350
|
+
def sint64
|
349
351
|
sint8 { |c| yield c * 8 }
|
350
352
|
end
|
351
353
|
|
data/lib/ronin/network.rb
CHANGED
@@ -20,10 +20,11 @@
|
|
20
20
|
require 'ronin/network/dns'
|
21
21
|
require 'ronin/network/tcp'
|
22
22
|
require 'ronin/network/udp'
|
23
|
-
require 'ronin/network/
|
23
|
+
require 'ronin/network/unix'
|
24
24
|
require 'ronin/network/smtp'
|
25
25
|
require 'ronin/network/esmtp'
|
26
26
|
require 'ronin/network/pop3'
|
27
27
|
require 'ronin/network/imap'
|
28
28
|
require 'ronin/network/telnet'
|
29
|
+
require 'ronin/network/ftp'
|
29
30
|
require 'ronin/network/http'
|
data/lib/ronin/network/dns.rb
CHANGED
@@ -42,7 +42,7 @@ module Ronin
|
|
42
42
|
#
|
43
43
|
# Sets the DNS nameserver to be queried.
|
44
44
|
#
|
45
|
-
# @param [IPAddr, String, nil]
|
45
|
+
# @param [IPAddr, String, nil] address
|
46
46
|
# The address of the nameserver.
|
47
47
|
#
|
48
48
|
# @return [String, nil]
|
@@ -84,18 +84,28 @@ module Ronin
|
|
84
84
|
# @param [String, nil] nameserver
|
85
85
|
# Optional DNS nameserver to query.
|
86
86
|
#
|
87
|
+
# @yield [address]
|
88
|
+
# If a block is given and the hostname was resolved, the address will
|
89
|
+
# be passed to the block.
|
90
|
+
#
|
91
|
+
# @yieldparam [String] address
|
92
|
+
# The address of the hostname.
|
93
|
+
#
|
87
94
|
# @return [String, nil]
|
88
95
|
# The address of the hostname.
|
89
96
|
#
|
90
97
|
# @api public
|
91
98
|
#
|
92
99
|
def dns_lookup(hostname,nameserver=DNS.nameserver)
|
93
|
-
|
100
|
+
hostname = hostname.to_s
|
101
|
+
resolv = dns_resolver(nameserver)
|
102
|
+
address = begin
|
103
|
+
resolv.getaddress(hostname).to_s
|
104
|
+
rescue Resolv::ResolvError
|
105
|
+
end
|
94
106
|
|
95
|
-
|
96
|
-
|
97
|
-
rescue Resolv::ResolvError
|
98
|
-
end
|
107
|
+
yield(address) if (block_given? && address)
|
108
|
+
return address
|
99
109
|
end
|
100
110
|
|
101
111
|
#
|
@@ -107,13 +117,24 @@ module Ronin
|
|
107
117
|
# @param [String, nil] nameserver
|
108
118
|
# Optional DNS nameserver to query.
|
109
119
|
#
|
120
|
+
# @yield [address]
|
121
|
+
# If a block is given, each resolved address will be passed to the
|
122
|
+
# block.
|
123
|
+
#
|
124
|
+
# @yieldparam [String] address
|
125
|
+
# A address of the hostname.
|
126
|
+
#
|
110
127
|
# @return [Array<String>]
|
111
128
|
# The addresses of the hostname.
|
112
129
|
#
|
113
130
|
# @api public
|
114
131
|
#
|
115
|
-
def dns_lookup_all(hostname,nameserver=DNS.nameserver)
|
116
|
-
|
132
|
+
def dns_lookup_all(hostname,nameserver=DNS.nameserver,&block)
|
133
|
+
hostname = hostname.to_s
|
134
|
+
addresses = dns_resolver(nameserver).getaddresses(hostname).map(&:to_s)
|
135
|
+
|
136
|
+
addresses.each(&block) if block
|
137
|
+
return addresses
|
117
138
|
end
|
118
139
|
|
119
140
|
#
|
@@ -125,18 +146,28 @@ module Ronin
|
|
125
146
|
# @param [String, nil] nameserver
|
126
147
|
# Optional DNS nameserver to query.
|
127
148
|
#
|
149
|
+
# @yield [hostname]
|
150
|
+
# If a block is given and a hostname was found for the address,
|
151
|
+
# the resolved hostname will be passed to the block.
|
152
|
+
#
|
153
|
+
# @yieldparam [String] hostname
|
154
|
+
# The hostname of the address.
|
155
|
+
#
|
128
156
|
# @return [String, nil]
|
129
157
|
# The hostname of the address.
|
130
158
|
#
|
131
159
|
# @api public
|
132
160
|
#
|
133
161
|
def dns_reverse_lookup(address,nameserver=DNS.nameserver)
|
134
|
-
|
162
|
+
address = address.to_s
|
163
|
+
resolv = dns_resolver(nameserver)
|
164
|
+
hostname = begin
|
165
|
+
resolv.getname(address).to_s
|
166
|
+
rescue Resolv::ResolvError
|
167
|
+
end
|
135
168
|
|
136
|
-
|
137
|
-
|
138
|
-
rescue Resolv::ResolvError
|
139
|
-
end
|
169
|
+
yield(hostname) if (block_given? && hostname)
|
170
|
+
return hostname
|
140
171
|
end
|
141
172
|
|
142
173
|
#
|
@@ -148,13 +179,24 @@ module Ronin
|
|
148
179
|
# @param [String, nil] nameserver
|
149
180
|
# Optional DNS nameserver to query.
|
150
181
|
#
|
182
|
+
# @yield [hostname]
|
183
|
+
# If a block is given and hostnames were found for the address,
|
184
|
+
# each hostname will be passed to the block.
|
185
|
+
#
|
186
|
+
# @yieldparam [String] hostname
|
187
|
+
# A hostname of the address.
|
188
|
+
#
|
151
189
|
# @return [Array<String>]
|
152
190
|
# The hostnames of the address.
|
153
191
|
#
|
154
192
|
# @api public
|
155
193
|
#
|
156
|
-
def dns_reverse_lookup_all(address,nameserver=DNS.nameserver)
|
157
|
-
|
194
|
+
def dns_reverse_lookup_all(address,nameserver=DNS.nameserver,&block)
|
195
|
+
address = address.to_s
|
196
|
+
hostnames = dns_resolver(nameserver).getnames(address).map(&:to_s)
|
197
|
+
|
198
|
+
hostnames.each(&block) if block
|
199
|
+
return hostnames
|
158
200
|
end
|
159
201
|
end
|
160
202
|
end
|
@@ -20,7 +20,6 @@
|
|
20
20
|
require 'ronin/network/extensions/dns'
|
21
21
|
require 'ronin/network/extensions/tcp'
|
22
22
|
require 'ronin/network/extensions/udp'
|
23
|
-
require 'ronin/network/extensions/ssl'
|
24
23
|
require 'ronin/network/extensions/smtp'
|
25
24
|
require 'ronin/network/extensions/esmtp'
|
26
25
|
require 'ronin/network/extensions/pop3'
|
@@ -0,0 +1,145 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2006-2012 Hal Brodigan (postmodern.mod3 at gmail.com)
|
3
|
+
#
|
4
|
+
# This file is part of Ronin Support.
|
5
|
+
#
|
6
|
+
# Ronin Support is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU Lesser General Public License as published
|
8
|
+
# by the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# Ronin Support is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU Lesser General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU Lesser General Public License
|
17
|
+
# along with Ronin Support. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
#
|
19
|
+
|
20
|
+
require 'net/ftp'
|
21
|
+
|
22
|
+
module Ronin
|
23
|
+
module Network
|
24
|
+
#
|
25
|
+
# Provides helper methods for communicating with FTP services.
|
26
|
+
#
|
27
|
+
# @since 0.5.0
|
28
|
+
#
|
29
|
+
module FTP
|
30
|
+
# Default FTP port
|
31
|
+
DEFAULT_PORT = 21
|
32
|
+
|
33
|
+
# Default FTP user
|
34
|
+
DEFAULT_USER = 'anonymous'
|
35
|
+
|
36
|
+
#
|
37
|
+
# Default port used by {FTP}.
|
38
|
+
#
|
39
|
+
# @return [Integer]
|
40
|
+
# The default Ronin FTP port.
|
41
|
+
#
|
42
|
+
# @api public
|
43
|
+
#
|
44
|
+
def self.default_port
|
45
|
+
@default_port ||= DEFAULT_PORT
|
46
|
+
end
|
47
|
+
|
48
|
+
#
|
49
|
+
# Sets the default port used by {FTP}.
|
50
|
+
#
|
51
|
+
# @param [Integer] new_port
|
52
|
+
# The new default Ronin FTP port.
|
53
|
+
#
|
54
|
+
# @api public
|
55
|
+
#
|
56
|
+
def self.default_port=(new_port)
|
57
|
+
@default_port = new_port
|
58
|
+
end
|
59
|
+
|
60
|
+
#
|
61
|
+
# Creates a connection to the FTP server.
|
62
|
+
#
|
63
|
+
# @param [String] host
|
64
|
+
# The host to connect to.
|
65
|
+
#
|
66
|
+
# @param [Hash] options
|
67
|
+
# Additional options.
|
68
|
+
#
|
69
|
+
# @option options [Integer] :port (FTP.default_port)
|
70
|
+
# The port to connect to.
|
71
|
+
#
|
72
|
+
# @option options [String] :user (DEFAULT_USER)
|
73
|
+
# The user to authenticate with.
|
74
|
+
#
|
75
|
+
# @option options [String] :password
|
76
|
+
# The password to authenticate with.
|
77
|
+
#
|
78
|
+
# @option options [String] :account
|
79
|
+
# The FTP account information to send via the `ACCT` command.
|
80
|
+
#
|
81
|
+
# @yield [session]
|
82
|
+
# If a block is given, it will be passed an FTP session object.
|
83
|
+
#
|
84
|
+
# @yieldparam [Net::FTP] session
|
85
|
+
# The FTP session.
|
86
|
+
#
|
87
|
+
# @return [Net::FTP]
|
88
|
+
# The FTP session.
|
89
|
+
#
|
90
|
+
# @example
|
91
|
+
# ftp_connect('www.example.com', :user => 'joe', :password => 'secret')
|
92
|
+
#
|
93
|
+
# @api public
|
94
|
+
#
|
95
|
+
def ftp_connect(host,options={})
|
96
|
+
host = host.to_s
|
97
|
+
port = (options[:port] || FTP.default_port)
|
98
|
+
user = (options[:user] || DEFAULT_USER)
|
99
|
+
password = options[:password]
|
100
|
+
acct = options[:account]
|
101
|
+
|
102
|
+
session = Net::FTP.new
|
103
|
+
session.connect(host,port)
|
104
|
+
session.login(user,password,acct)
|
105
|
+
|
106
|
+
yield session if block_given?
|
107
|
+
return session
|
108
|
+
end
|
109
|
+
|
110
|
+
#
|
111
|
+
# Starts a session with the FTP server.
|
112
|
+
#
|
113
|
+
# @param [String] host
|
114
|
+
# The host to connect to.
|
115
|
+
#
|
116
|
+
# @param [Hash] options
|
117
|
+
# Additional options.
|
118
|
+
#
|
119
|
+
# @yield [session]
|
120
|
+
# If a block is given, it will be passed an FTP session object.
|
121
|
+
# After the block has returned, the session will be closed.
|
122
|
+
#
|
123
|
+
# @yieldparam [Net::FTP] session
|
124
|
+
# The FTP session.
|
125
|
+
#
|
126
|
+
# @example
|
127
|
+
# ftp_session('www.example.com', :user => 'joe') do |ftp|
|
128
|
+
# # ...
|
129
|
+
# end
|
130
|
+
#
|
131
|
+
# @see #ftp_connect
|
132
|
+
#
|
133
|
+
# @api public
|
134
|
+
#
|
135
|
+
def ftp_session(host,options={})
|
136
|
+
ftp = ftp_connect(host,options)
|
137
|
+
|
138
|
+
yield ftp if block_given?
|
139
|
+
|
140
|
+
ftp.close
|
141
|
+
return nil
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|