Forum: Ruby on Rails Sending a file, FTP protocol

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Elias O. (Guest)
on 2008-12-19 20:31
(Received via mailing list)
Hello,

I was using the method send_file from an action on one of my
controllers to send a file to the users. The thing is that now the
file will be stored in an FTP and send_file only works with the HTTP
protocol. What can I do in this situation? This is what I had that
worked via HTTP:

  def get_it
      send_file "http://www.elioncho.com/uploads/babe.jpg"
  end
Frederick C. (Guest)
on 2008-12-19 20:49
(Received via mailing list)
On 19 Dec 2008, at 18:30, elioncho wrote:

>      send_file "http://www.elioncho.com/uploads/babe.jpg"
>  end

All send_file does it put the contents of a local file into your http
response. If you need to get a file from an ftp server and pass it to
the user I reckon you'd be better off redirecting them to the url. If
you need to save a file to an ftp server you could look into Net::FTP
(but that would block your mongrel for the duration of the transfer)

Fred
Elias O. (Guest)
on 2008-12-19 20:58
(Received via mailing list)
Hello Frederick,

Thanks for your input. In my case, the user should download the file
from the ftp server and when I use a redirect to the URL the file is
rendered on the browser (photo or mp3) and the URL becomes visible. My
goal is to hide the URL from where the file is coming and make the
user download the file locally.

Thanks again,

Elías

On Dec 19, 1:48 pm, Frederick C. <removed_email_address@domain.invalid>
Tim McIntyre (Guest)
on 2008-12-19 21:38
(Received via mailing list)
If the file is located on the same box as your web app you may want to
try sending the path as opposed to the complete url.  Just a thought:

 send_file "/full/path/uploads/babe.jpg"

Although the docs say the default is to send a binary attachment it
seems I had to play with the headers a bit, although i am using
mod_xsendfile (http://tn123.ath.cx/mod_xsendfile/) so that may have
mixed things up a bit can't recall.  I'm also doing:

render :nothing => true

at the end of my controller action.

Hope that helps, good luck!
Tim
Elias O. (Guest)
on 2008-12-19 21:50
(Received via mailing list)
Thanks Tim,

The thing is the user is going to download from a FTP server so I
can't use send_file.
Tim McIntyre (Guest)
on 2008-12-19 21:55
(Received via mailing list)
Is the FTP server running on the same box or the same local network.
If so is there some overriding reason that it has to be delivered via
FTP?
Elias O. (Guest)
on 2008-12-19 22:20
(Received via mailing list)
Hi Tim,

The files to download are on a FTP server. The user should be able to
copy a download code into a textfield and click a download button. The
file should automatically begin downloading and the URL should be
hidden. That's why initially I had the send_file option on a
controller action (when I thought it was via HTTP)

Thanks again,

Elías
This topic is locked and can not be replied to.