From a3bc4754630d88185066a4d5ba152f4a94287232 Mon Sep 17 00:00:00 2001 From: "William T. Nelson" <35801+wtn@users.noreply.github.com> Date: Mon, 16 Nov 2026 13:32:23 -0600 Subject: [PATCH] Raise FTPReplyError from mtime on non-213 reply `mdtm` returns nil when the MDTM reply is a positive reply other than 213, and `mtime` passed the nil to `TIME_PARSER`, which raised NoMethodError. `mtime` now raises FTPReplyError with the reply, as `size` does. Co-authored-by: Claude Opus 5.5 --- lib/net/ftp.rb | 6 +++++- test/net/ftp/test_ftp.rb | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/net/ftp.rb b/lib/net/ftp.rb index 261dd65..2789179 100644 --- a/lib/net/ftp.rb +++ b/lib/net/ftp.rb @@ -1229,7 +1229,11 @@ def size(filename) # +true+, it is returned as a local time, otherwise it's a UTC time. # def mtime(filename, local = false) - return TIME_PARSER.(mdtm(filename), local) + value = mdtm(filename) + unless value + raise FTPReplyError, @last_response + end + return TIME_PARSER.(value, local) end # diff --git a/test/net/ftp/test_ftp.rb b/test/net/ftp/test_ftp.rb index 34e11d0..19c82e5 100644 --- a/test/net/ftp/test_ftp.rb +++ b/test/net/ftp/test_ftp.rb @@ -1495,6 +1495,8 @@ def test_mtime sock.print("213 20150910161739.123456789\r\n") commands.push(sock.gets) sock.print("213 2015091016173\r\n") + commands.push(sock.gets) + sock.print("200 20150910161739\r\n") } begin begin @@ -1513,12 +1515,16 @@ def test_mtime assert_raise(Net::FTPProtoError) do ftp.mtime("quux.txt") end + assert_raise(Net::FTPReplyError) do + ftp.mtime("baz.txt") + end assert_match("MDTM foo.txt\r\n", commands.shift) assert_match("MDTM foo.txt\r\n", commands.shift) assert_match("MDTM bar.txt\r\n", commands.shift) assert_match("MDTM bar.txt\r\n", commands.shift) assert_match("MDTM bar.txt\r\n", commands.shift) assert_match("MDTM quux.txt\r\n", commands.shift) + assert_match("MDTM baz.txt\r\n", commands.shift) assert_equal(nil, commands.shift) ensure ftp.close if ftp