net-ftp 0.1.4 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 21c0eba7e609e9e211574f9516bcdeecd08cfccd970ad52f098838cddbba2b23
4
- data.tar.gz: f5e77d0c5fcf882ac5e9fa521fb29eed475fa5578886f1270c2b9047ba856b9d
3
+ metadata.gz: 18559c9c84d96f514739718efbda54e6fad17d4273091daa96439f8b2ca35088
4
+ data.tar.gz: 303c0fc5bfbf89f973b5dfc8adcab01353adbde0c1cc0a427ed5bcb545b680eb
5
5
  SHA512:
6
- metadata.gz: a022858433f6ddb623e6cc5a1f7b3ff01c686dbcff371530064b71b0d6fb39eb7e31a107a23d9bacbf9f52ef8bf0aeb09d5a651cd338bc37ecc76591e0a06cf7
7
- data.tar.gz: 416f37d820111d80b207ee426aa0007b237591d25662c6bb55de12483f0f8dd2d0f0ff0251d44dff594d5d46847c132b0ef97efa67ef12c4f756c712cb19650b
6
+ metadata.gz: d06b941364767d71f483fd1396328324b6c15c88072058f904ca69509f6e70c57c64a2c4c3e3ee041a23aaa5d83b598bcf16061e8b13b76056d405d64fb349de
7
+ data.tar.gz: 13234a36e3e7ab0d0026fe84c4ab42b61b3f7ca0354a78dbc98dcbee2e8402d4130658c327c6e1e2124096b4b1faa0092fdb8e159baef060b801746531120e71
@@ -0,0 +1,6 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: 'github-actions'
4
+ directory: '/'
5
+ schedule:
6
+ interval: 'weekly'
@@ -7,11 +7,11 @@ jobs:
7
7
  name: build (${{ matrix.ruby }} / ${{ matrix.os }})
8
8
  strategy:
9
9
  matrix:
10
- ruby: [ '3.0', 2.7, 2.6, 2.5, 2.4, head ]
10
+ ruby: [ head, '3.1', '3.0', '2.7', '2.6' ]
11
11
  os: [ ubuntu-latest, macos-latest ]
12
12
  runs-on: ${{ matrix.os }}
13
13
  steps:
14
- - uses: actions/checkout@v2
14
+ - uses: actions/checkout@v3
15
15
  - name: Set up Ruby
16
16
  uses: ruby/setup-ruby@v1
17
17
  with:
data/lib/net/ftp.rb CHANGED
@@ -85,7 +85,7 @@ module Net
85
85
  end
86
86
 
87
87
  # :stopdoc:
88
- VERSION = "0.1.4"
88
+ VERSION = "0.2.1"
89
89
  FTP_PORT = 21
90
90
  CRLF = "\r\n"
91
91
  DEFAULT_BLOCKSIZE = BufferedIO::BUFSIZE
@@ -106,6 +106,11 @@ module Net
106
106
  # to +$stdout+. Default: +false+.
107
107
  attr_accessor :debug_mode
108
108
 
109
+ # Sets or retrieves the output stream for debugging.
110
+ # Output stream will be used only when +debug_mode+ is set to true.
111
+ # The default value is +$stdout+.
112
+ attr_accessor :debug_output
113
+
109
114
  # Sets or retrieves the +resume+ status, which decides whether incomplete
110
115
  # transfers are resumed or restarted. Default: +false+.
111
116
  attr_accessor :resume
@@ -195,6 +200,8 @@ module Net
195
200
  # as parameters.
196
201
  # private_data_connection:: If true, TLS is used for data connections.
197
202
  # Default: +true+ when +options+[:ssl] is true.
203
+ # implicit_ftps:: If true, TLS is established on initial connection.
204
+ # Default: +false+
198
205
  # username:: Username for login. If +options+[:username] is the string
199
206
  # "anonymous" and the +options+[:password] is +nil+,
200
207
  # "anonymous@" is used as a password.
@@ -248,6 +255,11 @@ module Net
248
255
  else
249
256
  @private_data_connection = options[:private_data_connection]
250
257
  end
258
+ if options[:implicit_ftps].nil?
259
+ @implicit_ftps = false
260
+ else
261
+ @implicit_ftps = options[:implicit_ftps]
262
+ end
251
263
  else
252
264
  @ssl_context = nil
253
265
  if options[:private_data_connection]
@@ -255,6 +267,11 @@ module Net
255
267
  "private_data_connection can be set to true only when ssl is enabled"
256
268
  end
257
269
  @private_data_connection = false
270
+ if options[:implicit_ftps]
271
+ raise ArgumentError,
272
+ "implicit_ftps can be set to true only when ssl is enabled"
273
+ end
274
+ @implicit_ftps = false
258
275
  end
259
276
  @binary = true
260
277
  if options[:passive].nil?
@@ -267,6 +284,7 @@ module Net
267
284
  else
268
285
  @debug_mode = options[:debug_mode]
269
286
  end
287
+ @debug_output = $stdout
270
288
  @resume = false
271
289
  @bare_sock = @sock = NullSocket.new
272
290
  @logged_in = false
@@ -378,19 +396,17 @@ module Net
378
396
  # <tt>Errno::ECONNREFUSED</tt>) if the connection cannot be established.
379
397
  #
380
398
  def connect(host, port = FTP_PORT)
381
- if @debug_mode
382
- print "connect: ", host, ", ", port, "\n"
383
- end
399
+ debug_print "connect: #{host}:#{port}"
384
400
  synchronize do
385
401
  @host = host
386
402
  @bare_sock = open_socket(host, port)
387
- @sock = BufferedSocket.new(@bare_sock, read_timeout: @read_timeout)
388
- voidresp
389
403
  if @ssl_context
390
404
  begin
391
- voidcmd("AUTH TLS")
392
- ssl_sock = start_tls_session(@bare_sock)
393
- @sock = BufferedSSLSocket.new(ssl_sock, read_timeout: @read_timeout)
405
+ unless @implicit_ftps
406
+ set_socket(BufferedSocket.new(@bare_sock, read_timeout: @read_timeout))
407
+ voidcmd("AUTH TLS")
408
+ end
409
+ set_socket(BufferedSSLSocket.new(start_tls_session(@bare_sock), read_timeout: @read_timeout), @implicit_ftps)
394
410
  if @private_data_connection
395
411
  voidcmd("PBSZ 0")
396
412
  voidcmd("PROT P")
@@ -399,6 +415,8 @@ module Net
399
415
  @sock.close
400
416
  raise
401
417
  end
418
+ else
419
+ set_socket(BufferedSocket.new(@bare_sock, read_timeout: @read_timeout))
402
420
  end
403
421
  end
404
422
  end
@@ -430,9 +448,7 @@ module Net
430
448
  # Ensures that +line+ has a control return / line feed (CRLF) and writes
431
449
  # it to the socket.
432
450
  def putline(line) # :nodoc:
433
- if @debug_mode
434
- print "put: ", sanitize(line), "\n"
435
- end
451
+ debug_print "put: #{sanitize(line)}"
436
452
  if /[\r\n]/ =~ line
437
453
  raise ArgumentError, "A line must not contain CR or LF"
438
454
  end
@@ -445,9 +461,7 @@ module Net
445
461
  def getline # :nodoc:
446
462
  line = @sock.readline # if get EOF, raise EOFError
447
463
  line.sub!(/(\r\n|\n|\r)\z/n, "")
448
- if @debug_mode
449
- print "get: ", sanitize(line), "\n"
450
- end
464
+ debug_print "get: #{sanitize(line)}"
451
465
  return line
452
466
  end
453
467
  private :getline
@@ -545,7 +559,6 @@ module Net
545
559
  host, port = parse227(sendcmd("PASV"))
546
560
  else
547
561
  host, port = parse229(sendcmd("EPSV"))
548
- # host, port = parse228(sendcmd("LPSV"))
549
562
  end
550
563
  return host, port
551
564
  end
@@ -1248,7 +1261,7 @@ module Net
1248
1261
  #
1249
1262
  def abort
1250
1263
  line = "ABOR" + CRLF
1251
- print "put: ABOR\n" if @debug_mode
1264
+ debug_print "put: ABOR"
1252
1265
  @sock.send(line, Socket::MSG_OOB)
1253
1266
  resp = getmultiline
1254
1267
  unless ["426", "226", "225"].include?(resp[0, 3])
@@ -1268,7 +1281,7 @@ module Net
1268
1281
  if /[\r\n]/ =~ line
1269
1282
  raise ArgumentError, "A line must not contain CR or LF"
1270
1283
  end
1271
- print "put: #{line}\n" if @debug_mode
1284
+ debug_print "put: #{line}"
1272
1285
  @sock.send(line + CRLF, Socket::MSG_OOB)
1273
1286
  return getresp
1274
1287
  end
@@ -1401,24 +1414,6 @@ module Net
1401
1414
  end
1402
1415
  private :parse227
1403
1416
 
1404
- # handler for response code 228
1405
- # (Entering Long Passive Mode)
1406
- #
1407
- # Returns host and port.
1408
- def parse228(resp) # :nodoc:
1409
- if !resp.start_with?("228")
1410
- raise FTPReplyError, resp
1411
- end
1412
- if m = /\(4,4,(?<host>\d+(?:,\d+){3}),2,(?<port>\d+,\d+)\)/.match(resp)
1413
- return parse_pasv_ipv4_host(m["host"]), parse_pasv_port(m["port"])
1414
- elsif m = /\(6,16,(?<host>\d+(?:,\d+){15}),2,(?<port>\d+,\d+)\)/.match(resp)
1415
- return parse_pasv_ipv6_host(m["host"]), parse_pasv_port(m["port"])
1416
- else
1417
- raise FTPProtoError, resp
1418
- end
1419
- end
1420
- private :parse228
1421
-
1422
1417
  def parse_pasv_ipv4_host(s)
1423
1418
  return s.tr(",", ".")
1424
1419
  end
@@ -1466,6 +1461,13 @@ module Net
1466
1461
  end
1467
1462
  private :parse257
1468
1463
 
1464
+ #
1465
+ # Writes debug message to the debug output stream
1466
+ #
1467
+ def debug_print(msg)
1468
+ @debug_output << msg + "\n" if @debug_mode && @debug_output
1469
+ end
1470
+
1469
1471
  # :stopdoc:
1470
1472
  class NullSocket
1471
1473
  def read_timeout=(sec)
data/net-ftp.gemspec CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
16
16
  spec.summary = %q{Support for the File Transfer Protocol.}
17
17
  spec.description = %q{Support for the File Transfer Protocol.}
18
18
  spec.homepage = "https://github.com/ruby/net-ftp"
19
- spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
19
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.6.0")
20
20
  spec.licenses = ["Ruby", "BSD-2-Clause"]
21
21
 
22
22
  spec.metadata["homepage_uri"] = spec.homepage
@@ -25,10 +25,8 @@ Gem::Specification.new do |spec|
25
25
  # Specify which files should be added to the gem when it is released.
26
26
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
27
27
  spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
28
- `git ls-files -z 2>/dev/null`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
28
+ `git ls-files -z 2>/dev/null`.split("\x0").reject { |f| f.match(%r{^(bin|test|spec|features)/}) }
29
29
  end
30
- spec.bindir = "exe"
31
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
30
  spec.require_paths = ["lib"]
33
31
 
34
32
  spec.add_dependency "net-protocol"
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: net-ftp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shugo Maeda
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2024-01-05 00:00:00.000000000 Z
12
12
  dependencies:
@@ -45,14 +45,13 @@ executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
+ - ".github/dependabot.yml"
48
49
  - ".github/workflows/test.yml"
49
50
  - ".gitignore"
50
51
  - Gemfile
51
52
  - LICENSE.txt
52
53
  - README.md
53
54
  - Rakefile
54
- - bin/console
55
- - bin/setup
56
55
  - lib/net/ftp.rb
57
56
  - net-ftp.gemspec
58
57
  homepage: https://github.com/ruby/net-ftp
@@ -70,14 +69,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
70
69
  requirements:
71
70
  - - ">="
72
71
  - !ruby/object:Gem::Version
73
- version: 2.3.0
72
+ version: 2.6.0
74
73
  required_rubygems_version: !ruby/object:Gem::Requirement
75
74
  requirements:
76
75
  - - ">="
77
76
  - !ruby/object:Gem::Version
78
77
  version: '0'
79
78
  requirements: []
80
- rubygems_version: 3.3.27
79
+ rubygems_version: 3.4.19
81
80
  signing_key:
82
81
  specification_version: 4
83
82
  summary: Support for the File Transfer Protocol.
data/bin/console DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "net/ftp"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start(__FILE__)
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here