Ruby 如何在rails 3中通过ftp写入csv文件?

Ruby 如何在rails 3中通过ftp写入csv文件?,ruby,csv,ftp,libraries,Ruby,Csv,Ftp,Libraries,我正在尝试通过ftp写入csv文件。以下是我到目前为止的情况: require 'net/ftp' require 'csv' users = User.users.limit(5) csv_string = CSV.generate do |csv| csv << ["email_addr", "first_name", "last_name"] users.each do |user| new_line = [user.email, user.first_n

我正在尝试通过ftp写入csv文件。以下是我到目前为止的情况:

require 'net/ftp'
require 'csv'

users = User.users.limit(5)

csv_string = CSV.generate do |csv|
  csv << ["email_addr", "first_name", "last_name"]

  users.each do |user|
    new_line = [user.email, user.first_name, user.last_name]
    csv << new_line
  end
end

csv_file = CSV.new(csv_string)

ftp = Net::FTP.new('**SERVER NAME**')
ftp.login(user = "**USERNAME**", passwd = "**PASSWORD**")
ftp.storbinary('STOR ' + 'my_file.csv', csv_file)
ftp.quit()
我得到了错误的参数数2对3。当我将行更改为ftp.storbinary'STOR'+'my_file.csv',csv_file,1024时,表示0的参数1的数目错误。我也尝试过使用storlines,但这也给了我错误。有人对如何处理这件事有什么想法吗?

正在排队

ftp.storbinary('STOR ' + 'my_file.csv', csv_file)
csv_文件需要是实际的文件对象,而不是其他类型的对象

>来自ruby core storbinarycmd,文件,块大小,rest|u offset=nil{{| data |…}

将连接置于二进制映像模式,发出给定的服务器端 命令,并发送名为file的文件的内容 到服务器。如果给出了可选块,它也会以 块大小字符的块

require 'net/ftp'
登录到FTP服务器 或 切换到所需的目录 获取我们需要的文件并将其保存到我们的“ftp\u photos”目录 我们完成了,所以我们需要关闭连接
这会对你有帮助。

我的坏消息。我以为你是从环境局那里弄来的。
ftp = Net::FTP.new('ftp.sample.com', 'test', 'pass')
ftp = Net::FTP.new('ftp.sample.com')
ftp.login('test', 'pass')
ftp.chdir('source/files')
ftp.getbinaryfile('photos_2009-03-29.zip', 'ftp_photos/photos.zip')
ftp.close