From 52832c4db06949623620033c9383413707e7d205 Mon Sep 17 00:00:00 2001 From: usa Date: Fri, 27 Jun 2014 08:05:43 +0000 Subject: merge revision(s) 46182: [Backport #9872] * lib/net/ftp.rb (transfercmd): Close TCP server socket even if an exception occur. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@46577 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/net/ftp.rb | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'lib') diff --git a/lib/net/ftp.rb b/lib/net/ftp.rb index 805321c9d1..c2cf5f3af4 100644 --- a/lib/net/ftp.rb +++ b/lib/net/ftp.rb @@ -419,23 +419,26 @@ module Net end else sock = makeport - if @resume and rest_offset - resp = sendcmd("REST " + rest_offset.to_s) - if resp[0] != ?3 + begin + if @resume and rest_offset + resp = sendcmd("REST " + rest_offset.to_s) + if resp[0] != ?3 + raise FTPReplyError, resp + end + end + resp = sendcmd(cmd) + # skip 2XX for some ftp servers + resp = getresp if resp[0] == ?2 + if resp[0] != ?1 raise FTPReplyError, resp end + conn = BufferedSocket.new(sock.accept) + conn.read_timeout = @read_timeout + sock.shutdown(Socket::SHUT_WR) rescue nil + sock.read rescue nil + ensure + sock.close end - resp = sendcmd(cmd) - # skip 2XX for some ftp servers - resp = getresp if resp[0] == ?2 - if resp[0] != ?1 - raise FTPReplyError, resp - end - conn = BufferedSocket.new(sock.accept) - conn.read_timeout = @read_timeout - sock.shutdown(Socket::SHUT_WR) rescue nil - sock.read rescue nil - sock.close end return conn end -- cgit v1.2.3