Date: 2007-06-20 18:22
Sender: Daniel Berger
Yup, that's a bug. This patch fixes it:
--- ftp.orig Wed Jun 20 12:07:24 2007
+++ ftp.rb Wed Jun 20 12:18:31 2007
@@ -488,22 +488,27 @@
# chunks.
#
def getbinaryfile(remotefile, localfile =
File.basename(remotefile),
- blocksize = DEFAULT_BLOCKSIZE, &block) # :yield:
data
+ blocksize = DEFAULT_BLOCKSIZE, &block) # :yield: data
if @resume
- rest_offset = File.size?(localfile)
- f = open(localfile, "a")
+ rest_offset = File.size?(localfile)
+ f = open(localfile, "a")
else
- rest_offset = nil
- f = open(localfile, "w")
+ rest_offset = nil
+ f = open(localfile, "w")
end
+
begin
- f.binmode
- retrbinary("RETR " + remotefile, blocksize, rest_offset)
do |data|
- f.write(data)
- yield(data) if block
- end
+ f.binmode
+ retrbinary("RETR " + remotefile, blocksize,
rest_offset) do |data|
+ f.write(data)
+ yield(data) if block
+ end
+ rescue FTPError
+ f.close
+ File.delete(localfile) if File.exists?(localfile)
+ raise
ensure
- f.close
+ f.close unless f.closed?
end
end
@@ -515,12 +520,16 @@
def gettextfile(remotefile, localfile
= File.basename(remotefile), &block) # :yield: line
f = open(localfile, "w")
begin
- retrlines("RETR " + remotefile) do |line|
- f.puts(line)
- yield(line) if block
- end
+ retrlines("RETR " + remotefile) do |line|
+ f.puts(line)
+ yield(line) if block
+ end
+ rescue FTPError
+ f.close
+ File.delete(localfile) if File.exists?(localfile)
+ raise
ensure
- f.close
+ f.close unless f.closed?
end
end |