net/ftp – Rubygem

Download and read the file using net/ftp

  

require ‘rubygems’
require ‘net/ftp’

ftp=Net::FTP.new(‘100.444.211.144’)

ftp.login
ftp.chdir(“/Main_flder/Sub_folder1/Sub_folder2/”)
fileList = ftp.nlst(‘*.txt’)  #instead of .txt you can use any file extension

filedata = ‘ ‘

ftp.retrlines(“RETR ” + fileList[0]) do |block|
filedata << block

end

puts filedata    # It will print the content of the entire TEXT FILE

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s