我有一个 rake 任务,它连接到一个 ftp 服务器,下载一个文件,然后对其进行压缩。这在本地工作,但是当我在 heroku cedar 服务器上运行任务时,在执行 net::ftp.getbinaryfile 后我没有得到任何反馈。
这是下载文件的代码:
tempfile = "#{Rails.root}/tmp/#{Process.pid}_#{MyApp::Application.config.products_bbcom_file}"
ftp = Net::FTP.new()
puts "connecting to ftp server #{MyApp::Application.config.products_bbcom_host}"
ftp.connect(MyApp::Application.config.products_bbcom_host)
puts "logging in"
ftp.login(MyApp::Application.config.products_bbcom_user,MyApp::Application.config.products_bbcom_pass)
puts "changing directory"
files = ftp.chdir(MyApp::Application.config.products_bbcom_path)
#files = ftp.list('n*')
puts "downloading file #{MyApp::Application.config.products_bbcom_file} to #{tempfile}"
ftp.getbinaryfile(MyApp::Application.config.products_bbcom_file, tempfile, 1024)
ftp.close
当我在 heroku 上执行任务时: heroku run rake db:import 并跟踪我看到的日志:
2012-09-10T16:26:24+00:00 heroku[run.1]: Awaiting client
2012-09-10T16:26:24+00:00 heroku[run.1]: Starting process with command `bundle exec rake db:import`
2012-09-10T16:26:25+00:00 heroku[run.1]: State changed from starting to up
任务的输出是:
== Starting ==
Connecting to database specified by DATABASE_URL
connecting to ftp server datatransfer.cj.com
logging in
changing directory
downloading file
脚本到达尝试将文件下载到 #{Rails.root}/tmp/ 但不再响应的地步。这在本地只需要几秒钟,但我等了几分钟,任务没有做任何事情。
从 heroku 开发站点看来,您可以将文件保存到 cedar 上的 #{Rails.root}/tmp/ 。这可能吗?如果是这样,我是否采取了错误的方法?