harishanchu / Laravel-FTP

A simple Laravel 4/5/6/7 ftp service provider with basic ftp methods.
220 stars 87 forks source link

Download a large file to the browser directly #65

Closed ozzargueyo closed 6 years ago

ozzargueyo commented 7 years ago

Hi, nice library. I am trying to download a large file, an PSD file, that is in a remote ftp server that I owned. I'm developing a web app that can download directly to the user's browser. Is there a way to do this, without download it in my server and then to the user?

Thanks!

emilv commented 6 years ago

There are these three options:

  1. Provide the user with a link to an FTP URL: ftp://user:password@example.com/path/to/file.psd
  2. Download the file to your server first, then send it to your user. You can use this library's downloadFile function followed by readfile
  3. Stream the file through your server but send it to the user immediately. You can use this library's readFile function, or for example the Flysystem streaming functions.

Option 1 leaks the username and password so you have to trust the user you give the link to.

Option 2 and 3 both requires the file to pass through your server so you have to pay for the bandwidth. Option 3 needs some tinkering to make it actually stream the file. If you do it wrong it will just end up in the output buffer and act exactly like in option 2.

There is no way to stream the file directly to the browser without giving away the username and password.