End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
Net::FTP#gettextfile
gettextfile(remotefile, localfile = File.basename(remotefile)) { |line| ... }
lib/net/ftp.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.0.5/lib/net/ftp.rb, line 804
def gettextfile(remotefile, localfile = File.basename(remotefile),
&block) # :yield: line
f = nil
result = nil
if localfile
f = File.open(localfile, "w")
elsif !block_given?
result = String.new
end
begin
retrlines("RETR #{remotefile}") do |line, newline|
l = newline ? line + "\n" : line
f&.print(l)
block&.(line, newline)
result&.concat(l)
end
return result
ensure
f&.close
end
end
Retrieves remotefile in ASCII (text) mode, storing the result in localfile. If localfile is nil, returns retrieved data. If a block is supplied, it is passed the retrieved data one line at a time.