Faster FTP get in Ruby
Get faster FTP transfer with FTP lib in Ruby by disabling reverse DNS lookup (it can be very slow):
Use:
BasicSocket.do_not_reverse_lookup = true
ftp = Net::FTP.new('server', 'user', 'password')
Full example:
def download_file(file)
BasicSocket.do_not_reverse_lookup = true
ftp = Net::FTP.new('server', 'user', 'password')
ftp.passive = true
begin
logger.info "info: Downloading #{file}."
ftp.getbinaryfile(File.basename(file), file, 1024)
rescue Net::FTPPermError => e
logger.info "warning: can't download #{File.basename(file)} from the remote server (#{e.message.tr("\n","")})."
end
ftp.close
end
Written by Pablo Torrecilla
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#