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