【发布时间】:2011-02-12 04:43:36
【问题描述】:
我正在使用 Rails 2.3.5 和 Ruby 1.8.6,并试图弄清楚如何让用户通过我的 Rails 应用程序将文件上传到另一台机器上的 FTP 服务器。此外,我的 Rails 应用程序将托管在 Heroku 上,这不利于将文件写入本地文件系统。
index.html.erb
<% form_tag '/ftp/upload', :method => :post, :multipart => true do %>
<label for="file">File to Upload</label> <%= file_field_tag "file" %>
<%= submit_tag 'Upload' %>
<% end %>
ftp_controller.rb
require 'net/ftp'
class FtpController < ApplicationController
def upload
file = params[:file]
ftp = Net::FTP.new('remote-ftp-server')
ftp.login(user = "***", passwd = "***")
ftp.putbinaryfile(file.read, File.basename(file.original_filename))
ftp.quit()
end
def index
end
end
目前我只是想让 Rails 应用程序在我的 Windows 笔记本电脑上运行。使用上面的代码,我得到了这个错误
Errno::ENOENT in FtpController#upload
No such file or directory -.... followed by a dump of the file contents
我正在尝试上传一个 CSV 文件,如果这有什么不同的话。有谁知道怎么回事?
【问题讨论】:
标签: ruby-on-rails ftp