0

I have an FTP server with a public IP which is used to share files with other users who can just download without authenticating (for example ftp://88.88.111.111/file.txt). As you may know, recently Gooogle Chrome started filtering FTP connections. (I know there are some workarounds for that but I am interested in an alternative solution.)

What I would like to implement is a PHP interface from the server which hosts my website (and which supports HTTPS connection), so a user can go to https://www.mywebsite.com/interface.php?get=file.txt and they will actually download on their computer the file taken from ftp://88.88.111.111/file.txt. So, the user won't use any FTP connection and this is totally hidden. (I don't know if I explained my idea clearly)

I am not an expert about that, so I would like to understand if it can be done and if you have some indication about how to implement that.

Thanks in advance!

  • 3
    There are a couple of ways to do this. If the FTP server is on the same machine as the web server, you can cut out the FTP part for the web version and just look at the disk. If they are on separate machine, you can still do the same as the previous but use an abstraction such as [Flysystem](https://flysystem.thephpleague.com/v1/docs/adapter/ftp/). Otherwise, you can just build your own using [FTP functions](https://www.php.net/manual/en/book.ftp.php) which isn't that pretty, just to warn you. – Chris Haas Apr 08 '21 at 19:36
  • They are on separate machines. Thanks for the suggestions, I will look at them! – 3R_LikeNoOther Apr 08 '21 at 19:48

1 Answers1

1

You could do something like this to download the files from the FTP server, to the web-server and then let the user download the file from the web-server.

$file_url = "ftp://88.88.111.111/" . $_GET['file'];
$file_tmp = file_get_contents($file_url);
file_put_contents("/var/www/html/files/ . $file_tmp);
$download_url = "https://www.mywebsite.com/files/" . $_GET['file'];
header('Location: $download_url');
exit;
  • 1
    There's no need to store the file on the web server. See [Download file via PHP script from FTP server to browser with Content-Length header without storing the file on the web server](https://stackoverflow.com/q/47240635/850848). – Martin Prikryl Apr 08 '21 at 20:07
  • Thanks to everybody for the help! I was able to do that with just 10 lines of code – 3R_LikeNoOther Apr 09 '21 at 12:58