ruby - Retrieving text file using Net::FTP without login -


i'm starting learn ruby, 1 of first projects develop metar logger writes mysql database. however, i'm running issue getting actual source string national weather service.

the national weather service/noaa makes metar reports available via text file stored on ftp server (i.e. here), using net::http out of question. thing can't figure out how do, though, how access ftp server (or, @ least, obtain file) without ftp credentials - works fine credential-less above (direct url) access.

i found this link on ruby forum coincidentally trying same thing was, , tried stripped-down version of code see if hang of it, namely:

require 'net/ftp'  def getmetardata (id)     ftp = net::ftp.new ('tgftp.nws.noaa.gov')     ftp.chdir ('/data/observations/metar/stations')     metardata = ftp.gettextfile ("#{id.upcase}.txt")     ftp.close     return metardata end  puts getmetardata ("ksfo") 

however, when attempt run $ ruby test.rb, following error:

test.rb:29: warning: assigned unused variable - metardata <...>/net/ftp.rb:327:in `getresp': 530 please login user , pass. (net::ftppermerror) 

attempting issue blank login (ftp.login) , ftp passive command after net::ftp instantiation not work either. gives different error:

test.rb:31: warning: assigned unused variable - metardata <...>/net/ftp.rb:327:in `getresp': 550 permission denied. (net::ftppermerror) 

any ideas on how alleviate issue?

also, in full disclosure,

  • yes, did try using net:http directly access url above, didn't put possibility here because shot in dark
  • i'm not using 1 of already-available metar retrieval , parsing libraries (example) because want hang of working strings , ruby syntax in general.

edit

after following @infused's answer log in anonymously, placed puts on both ftp.login , ftp.sendcmd. following string of errors results when run:

true 227 entering passive mode (140,90,101,79,6,131). /users/blasthash/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/net/ftp.rb:327:in `getresp': 550 permission denied. (net::ftppermerror) /users/blasthash/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/net/ftp.rb:339:in `voidresp' /users/blasthash/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/net/ftp.rb:362:in `block in voidcmd' /users/blasthash/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize' /users/blasthash/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/net/ftp.rb:360:in `voidcmd' /users/blasthash/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/net/ftp.rb:376:in `sendport' /users/blasthash/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/net/ftp.rb:387:in `makeport' /users/blasthash/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/net/ftp.rb:422:in `transfercmd' /users/blasthash/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/net/ftp.rb:518:in `block (2 levels) in retrlines' /users/blasthash/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/net/ftp.rb:199:in `with_binary' /users/blasthash/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/net/ftp.rb:516:in `block in retrlines' /users/blasthash/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize' /users/blasthash/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/net/ftp.rb:515:in `retrlines' /users/blasthash/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/net/ftp.rb:647:in `gettextfile' test.rb:30:in `getmetardata' test.rb:35:in `<main>' 

login using username "anonymous" , either "guest" or email address password:

ftp = net::ftp.new ('tgftp.nws.noaa.gov') ftp.passive = true ftp.login 'anonymous', 'guest' ftp.chdir ('/data/observations/metar/stations') ... 

you'll find more info anonymous ftp here.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -