Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/net/ftp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

#
Expand Down
6 changes: 6 additions & 0 deletions test/net/ftp/test_ftp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down