diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/net/ftp.rb | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/net/ftp.rb b/lib/net/ftp.rb index b34c648bf3..6f5f848070 100644 --- a/lib/net/ftp.rb +++ b/lib/net/ftp.rb @@ -87,8 +87,20 @@ module Net # # A synonym for +FTP.new+, but with a mandatory host parameter. # + # If a block is given, it is passed the +FTP+ object, which will be closed + # when the block finishes, or when an exception is raised. + # def FTP.open(host, user = nil, passwd = nil, acct = nil) - new(host, user, passwd, acct) + if block_given? + ftp = new(host, user, passwd, acct) + begin + yield ftp + ensure + ftp.close + end + else + new(host, user, passwd, acct) + end end # |