I have a website developed under CakePHP. I'm trying to change the download system from Apache to FTP.
I currently am doing the FTP by hand with PHP (not using any plugins or libraries).
My code succesfully connects to the FTP server etc. The problem I'm having is that when I call ftp_get($conn_id, $localFile, $remoteFile, FTP_BINARY)
, it succesfully executes, though the file does not download, instead, its moved to the /webroot/ folder, which serves, as the name suggests, as the root folder of the website (using .httaccess rules).
I mention the .httaccess because I may suspect this is what causing the FTP to route the download to "moving" it to the root, but I'm not sure.
The following is my FTP download code:
$conn_id = ftp_connect($host);
$login_result = ftp_login($conn_id,$ftp_user,$ftp_pass);
if($login_result)
{
try
{
if(ftp_get($conn_id, $localFile, $remoteFile, FTP_BINARY))
{
$this->log("Downloaded...","debug");
}
else
{
$this->log("Couldn't download...","debug");
}
}
catch(Exception $e)
{
$this->log("Error: " . $e->getMessage(),"debug");
}
}
else
{
$this->log("Coudln't connect to FTP server...","debug");
}
ftp_close($conn_id);
Yes, I checked (printed out) the $conn_id
and the $login_result
and they are working.
What is inside the paths?
$remoteFile = "/downloads/rdticoiroe1432584529/YourMusic.zip";
$localFile = "Music.zip";
The code does not throw any errors. I also tried using the fotografde/cakephp-ftp
repo plugin for cakephp and FTP, and it does the same behaviour...
EDIT 1:
Its a music download site, right now we serve file downloads with Apache (which is very slow), the idea is to move to FTP downloads. I'm trying to use FTP protocol to download the file when the client requests download of it.
EDIT 2:
The whole idea of this question, is me trying to move to a more optimized method to serve files to clients. I own a 100Mbit transfer server and downloads are preeetty slow. I'm using Apache at the moment to download files to clients who request it.
I completely misunderstood about using PHP-FTP to serve files to the clients Hard Drive.
So, I'm looking for some guidance at what methods/protocols do people use when they serve files to clients who request download. (This is a music download site).