aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNARUSE, Yui <naruse@airemix.jp>2019-12-10 19:25:00 +0900
committerNARUSE, Yui <naruse@airemix.jp>2019-12-17 08:24:47 +0900
commit5be34d6a3310065850c0c530db6936415124b5d9 (patch)
tree1cd43be744c78116a7924dc8e930cb4b9f469bee
parent95213f6df6a23918d57a743975708c638da42aae (diff)
downloadruby-5be34d6a3310065850c0c530db6936415124b5d9.tar.gz
ensure to close the data connection [Bug #16413]
-rw-r--r--lib/net/ftp.rb44
1 files changed, 28 insertions, 16 deletions
diff --git a/lib/net/ftp.rb b/lib/net/ftp.rb
index fbee888685..b20f84b206 100644
--- a/lib/net/ftp.rb
+++ b/lib/net/ftp.rb
@@ -686,14 +686,20 @@ module Net
end
synchronize do
with_binary(true) do
- conn = transfercmd(cmd)
- loop do
- buf = file.read(blocksize)
- break if buf == nil
- conn.write(buf)
- yield(buf) if block_given?
+ begin
+ conn = transfercmd(cmd)
+ loop do
+ buf = file.read(blocksize)
+ break if buf == nil
+ conn.write(buf)
+ yield(buf) if block_given?
+ end
+ conn.shutdown(Socket::SHUT_WR)
+ conn.read_timeout = 1
+ conn.read
+ ensure
+ conn.close if conn
end
- conn.close
voidresp
end
end
@@ -715,17 +721,23 @@ module Net
def storlines(cmd, file) # :yield: line
synchronize do
with_binary(false) do
- conn = transfercmd(cmd)
- loop do
- buf = file.gets
- break if buf == nil
- if buf[-2, 2] != CRLF
- buf = buf.chomp + CRLF
+ begin
+ conn = transfercmd(cmd)
+ loop do
+ buf = file.gets
+ break if buf == nil
+ if buf[-2, 2] != CRLF
+ buf = buf.chomp + CRLF
+ end
+ conn.write(buf)
+ yield(buf) if block_given?
end
- conn.write(buf)
- yield(buf) if block_given?
+ conn.shutdown(Socket::SHUT_WR)
+ conn.read_timeout = 1
+ conn.read
+ ensure
+ conn.close if conn
end
- conn.close
voidresp
end
end