net-ftp 0.1.1 → 0.1.3
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 +4 -4
- data/.github/workflows/test.yml +3 -5
- data/.gitignore +1 -0
- data/lib/net/ftp.rb +44 -21
- metadata +3 -4
- data/Gemfile.lock +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a662c5a1b1201b6381d8c674ef0fcbe4a5a882ca023a24bd0606b607ec2a9cf
|
4
|
+
data.tar.gz: a89263fa37869d75365ffa13206244fae8efcaa2dcd8a24aa032ebdaf58bbbd4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd09e0b10d7188943dcbdf8a7af4482d2798f4207fbdd5e42c44e6156ccb40b29e6f026b38c773d10b69e3549776ee79a266a1c7fb33315ad899faf0e25852f9
|
7
|
+
data.tar.gz: 76ca5bc18729d1ad8f0aaf732845a08ed6d21539d60db29bdadab43d9d3801f53772fd9312f1bd900fbd4e16f533b61b2c08cf60bfef87f4a3ebb7ced2e51630
|
data/.github/workflows/test.yml
CHANGED
@@ -7,18 +7,16 @@ jobs:
|
|
7
7
|
name: build (${{ matrix.ruby }} / ${{ matrix.os }})
|
8
8
|
strategy:
|
9
9
|
matrix:
|
10
|
-
ruby: [ 2.7, 2.6, 2.5, 2.4, head ]
|
10
|
+
ruby: [ '3.0', 2.7, 2.6, 2.5, 2.4, head ]
|
11
11
|
os: [ ubuntu-latest, macos-latest ]
|
12
12
|
runs-on: ${{ matrix.os }}
|
13
13
|
steps:
|
14
|
-
- uses: actions/checkout@
|
14
|
+
- uses: actions/checkout@v2
|
15
15
|
- name: Set up Ruby
|
16
16
|
uses: ruby/setup-ruby@v1
|
17
17
|
with:
|
18
18
|
ruby-version: ${{ matrix.ruby }}
|
19
19
|
- name: Install dependencies
|
20
|
-
run:
|
21
|
-
gem install bundler --no-document
|
22
|
-
bundle install
|
20
|
+
run: bundle install
|
23
21
|
- name: Run test
|
24
22
|
run: rake test
|
data/.gitignore
CHANGED
data/lib/net/ftp.rb
CHANGED
@@ -85,7 +85,7 @@ module Net
|
|
85
85
|
end
|
86
86
|
|
87
87
|
# :stopdoc:
|
88
|
-
VERSION = "0.1.
|
88
|
+
VERSION = "0.1.3"
|
89
89
|
FTP_PORT = 21
|
90
90
|
CRLF = "\r\n"
|
91
91
|
DEFAULT_BLOCKSIZE = BufferedIO::BUFSIZE
|
@@ -98,6 +98,10 @@ module Net
|
|
98
98
|
# When +true+, the connection is in passive mode. Default: +true+.
|
99
99
|
attr_accessor :passive
|
100
100
|
|
101
|
+
# When +true+, use the IP address in PASV responses. Otherwise, it uses
|
102
|
+
# the same IP address for the control connection. Default: +false+.
|
103
|
+
attr_accessor :use_pasv_ip
|
104
|
+
|
101
105
|
# When +true+, all traffic to and from the server is written
|
102
106
|
# to +$stdout+. Default: +false+.
|
103
107
|
attr_accessor :debug_mode
|
@@ -206,6 +210,9 @@ module Net
|
|
206
210
|
# handshake.
|
207
211
|
# See Net::FTP#ssl_handshake_timeout for
|
208
212
|
# details. Default: +nil+.
|
213
|
+
# use_pasv_ip:: When +true+, use the IP address in PASV responses.
|
214
|
+
# Otherwise, it uses the same IP address for the control
|
215
|
+
# connection. Default: +false+.
|
209
216
|
# debug_mode:: When +true+, all traffic to and from the server is
|
210
217
|
# written to +$stdout+. Default: +false+.
|
211
218
|
#
|
@@ -266,6 +273,7 @@ module Net
|
|
266
273
|
@open_timeout = options[:open_timeout]
|
267
274
|
@ssl_handshake_timeout = options[:ssl_handshake_timeout]
|
268
275
|
@read_timeout = options[:read_timeout] || 60
|
276
|
+
@use_pasv_ip = options[:use_pasv_ip] || false
|
269
277
|
if host
|
270
278
|
connect(host, options[:port] || FTP_PORT)
|
271
279
|
if options[:username]
|
@@ -330,14 +338,19 @@ module Net
|
|
330
338
|
# SOCKS_SERVER, then a SOCKSSocket is returned, else a Socket is
|
331
339
|
# returned.
|
332
340
|
def open_socket(host, port) # :nodoc:
|
333
|
-
|
334
|
-
|
335
|
-
|
341
|
+
if defined? SOCKSSocket and ENV["SOCKS_SERVER"]
|
342
|
+
@passive = true
|
343
|
+
Timeout.timeout(@open_timeout, OpenTimeout) do
|
336
344
|
SOCKSSocket.open(host, port)
|
337
|
-
else
|
338
|
-
Socket.tcp(host, port)
|
339
345
|
end
|
340
|
-
|
346
|
+
else
|
347
|
+
begin
|
348
|
+
Socket.tcp host, port, nil, nil, connect_timeout: @open_timeout
|
349
|
+
rescue Errno::ETIMEDOUT #raise Net:OpenTimeout instead for compatibility with previous versions
|
350
|
+
raise Net::OpenTimeout, "Timeout to open TCP connection to "\
|
351
|
+
"#{host}:#{port} (exceeds #{@open_timeout} seconds)"
|
352
|
+
end
|
353
|
+
end
|
341
354
|
end
|
342
355
|
private :open_socket
|
343
356
|
|
@@ -542,18 +555,22 @@ module Net
|
|
542
555
|
def transfercmd(cmd, rest_offset = nil) # :nodoc:
|
543
556
|
if @passive
|
544
557
|
host, port = makepasv
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
558
|
+
begin
|
559
|
+
conn = open_socket(host, port)
|
560
|
+
if @resume and rest_offset
|
561
|
+
resp = sendcmd("REST " + rest_offset.to_s)
|
562
|
+
if !resp.start_with?("3")
|
563
|
+
raise FTPReplyError, resp
|
564
|
+
end
|
565
|
+
end
|
566
|
+
resp = sendcmd(cmd)
|
567
|
+
# skip 2XX for some ftp servers
|
568
|
+
resp = getresp if resp.start_with?("2")
|
569
|
+
if !resp.start_with?("1")
|
549
570
|
raise FTPReplyError, resp
|
550
571
|
end
|
551
|
-
|
552
|
-
|
553
|
-
# skip 2XX for some ftp servers
|
554
|
-
resp = getresp if resp.start_with?("2")
|
555
|
-
if !resp.start_with?("1")
|
556
|
-
raise FTPReplyError, resp
|
572
|
+
ensure
|
573
|
+
conn.close if conn && $!
|
557
574
|
end
|
558
575
|
else
|
559
576
|
sock = makeport
|
@@ -1045,10 +1062,11 @@ module Net
|
|
1045
1062
|
TIME_PARSER = ->(value, local = false) {
|
1046
1063
|
unless /\A(?<year>\d{4})(?<month>\d{2})(?<day>\d{2})
|
1047
1064
|
(?<hour>\d{2})(?<min>\d{2})(?<sec>\d{2})
|
1048
|
-
(?:\.(?<fractions>\d
|
1065
|
+
(?:\.(?<fractions>\d{1,17}))?/x =~ value
|
1066
|
+
value = value[0, 97] + "..." if value.size > 100
|
1049
1067
|
raise FTPProtoError, "invalid time-val: #{value}"
|
1050
1068
|
end
|
1051
|
-
usec = fractions.
|
1069
|
+
usec = ".#{fractions}".to_r * 1_000_000 if fractions
|
1052
1070
|
Time.public_send(local ? :local : :utc, year, month, day, hour, min, sec, usec)
|
1053
1071
|
}
|
1054
1072
|
FACT_PARSERS = Hash.new(CASE_DEPENDENT_PARSER)
|
@@ -1356,7 +1374,7 @@ module Net
|
|
1356
1374
|
end
|
1357
1375
|
|
1358
1376
|
#
|
1359
|
-
# Returns +true+
|
1377
|
+
# Returns +true+ if and only if the connection is closed.
|
1360
1378
|
#
|
1361
1379
|
def closed?
|
1362
1380
|
@sock == nil or @sock.closed?
|
@@ -1371,7 +1389,12 @@ module Net
|
|
1371
1389
|
raise FTPReplyError, resp
|
1372
1390
|
end
|
1373
1391
|
if m = /\((?<host>\d+(?:,\d+){3}),(?<port>\d+,\d+)\)/.match(resp)
|
1374
|
-
|
1392
|
+
if @use_pasv_ip
|
1393
|
+
host = parse_pasv_ipv4_host(m["host"])
|
1394
|
+
else
|
1395
|
+
host = @bare_sock.remote_address.ip_address
|
1396
|
+
end
|
1397
|
+
return host, parse_pasv_port(m["port"])
|
1375
1398
|
else
|
1376
1399
|
raise FTPProtoError, resp
|
1377
1400
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: net-ftp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shugo Maeda
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: net-protocol
|
@@ -48,7 +48,6 @@ files:
|
|
48
48
|
- ".github/workflows/test.yml"
|
49
49
|
- ".gitignore"
|
50
50
|
- Gemfile
|
51
|
-
- Gemfile.lock
|
52
51
|
- LICENSE.txt
|
53
52
|
- README.md
|
54
53
|
- Rakefile
|
@@ -78,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
78
77
|
- !ruby/object:Gem::Version
|
79
78
|
version: '0'
|
80
79
|
requirements: []
|
81
|
-
rubygems_version: 3.
|
80
|
+
rubygems_version: 3.3.0.dev
|
82
81
|
signing_key:
|
83
82
|
specification_version: 4
|
84
83
|
summary: Support for the File Transfer Protocol.
|
data/Gemfile.lock
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
net-ftp (0.1.0)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: https://rubygems.org/
|
8
|
-
specs:
|
9
|
-
power_assert (1.1.5)
|
10
|
-
rake (13.0.1)
|
11
|
-
test-unit (3.3.5)
|
12
|
-
power_assert
|
13
|
-
|
14
|
-
PLATFORMS
|
15
|
-
ruby
|
16
|
-
|
17
|
-
DEPENDENCIES
|
18
|
-
net-ftp!
|
19
|
-
rake
|
20
|
-
test-unit
|
21
|
-
|
22
|
-
BUNDLED WITH
|
23
|
-
2.1.4
|