0

I have a "Rule list" on "localhost:3000/rules" and its JSON render on "localhost:3000/rules.json"

I want to creat the action "Publish" to upload this json to my FTP but I don't find the solution to make this with Net:FTP.

Here's my code : rules_controller.rb

def publish
   require 'net/ftp'
   ftp = Net::FTP.new('xxxxxx', 'xxxxxxxx', 'xxxxxxx')
   ftp.chdir('www/lol')
   ftp.putbinaryfile('rules.json')
   ftp.close
end

Thanks in advance

1 Answers1

1

Never worked on this but looking at [ http://stdlib.rubyonrails.org/libdoc/net/ftp/rdoc/classes/Net/FTP.html ] It seems ftp.login part is missing.

Well, if you dont need to be authenticated, then need some more insight to give any suggestion. Can you post the problem that you are facing exactly?


Edit:

If you can have your json data (containing all the rules) in a file(like you said rules.json), this net/ftp should work. Now if you are facing problem with saving the json content in a temporary file, this post - " File.open, write and save? " might help. But if you feel that the problem lies completely in net/ftp, then a error log or more detail description of the problem would be helpful.

Community
  • 1
  • 1
Samiron
  • 5,169
  • 2
  • 28
  • 55
  • Thanks for your answer. The login is not a problem, it seems we can avoid ftp.login by using FTP.new('host', 'login', 'pw') Like I said, I want to upload a JSON with all my "Rules" on my FTP. I tried to put them on a variable but of course it doesn't work with "putbinaryfile" so I tried to use the Index action of my Controller Rules who has already a JSON render but it doesn't work neither. – Baptiste Pillon Aug 24 '12 at 17:06
  • Yes, Sorry, I missed the `login` part of `new` method. However, Ive updated my answer with something more. Let me know if it could help or not. – Samiron Aug 24 '12 at 18:54
  • Thanks a lot ! It seems that it works with a "temporary" file before FTP upload :) – Baptiste Pillon Aug 26 '12 at 11:32