简体   繁体   English

ftp_get()不下载,而是将文件移动到网站根文件夹

[英]ftp_get() does not download, instead moves file to website root folder

I have a website developed under CakePHP. 我有一个在CakePHP下开发的网站。 I'm trying to change the download system from Apache to FTP. 我正在尝试将下载系统从Apache更改为FTP。

I currently am doing the FTP by hand with PHP (not using any plugins or libraries). 我目前正在用PHP手动进行FTP(不使用任何插件或库)。

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). 我的代码成功连接到FTP服务器等。我遇到的问题是,当我调用ftp_get($conn_id, $localFile, $remoteFile, FTP_BINARY) ,它成功执行,尽管文件未下载,但已移动到/ webroot /文件夹,顾名思义,该文件夹用作网站的根文件夹(使用.httaccess规则)。

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. 我之所以提到.httaccess,是因为我可能怀疑这是FTP导致将下载路由“移动”到根目录的原因,但是我不确定。

The following is my FTP download code: 以下是我的FTP下载代码:

    $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. 是的,我检查了(打印出) $conn_id$login_result ,它们正在工作。

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... 我也尝试过使用用于cakephp和FTP的fotografde/cakephp-ftp repo插件,它的行为相同。

EDIT 1: 编辑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. 它是一个音乐下载站点,现在我们通过Apache提供文件下载服务(这非常慢),其思想是转向FTP下载。 I'm trying to use FTP protocol to download the file when the client requests download of it. 当客户端请求下载文件时,我正在尝试使用FTP协议下载文件。

EDIT 2: 编辑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. 我拥有一个100Mbit的传输服务器,下载速度非常慢。 I'm using Apache at the moment to download files to clients who request it. 我目前正在使用Apache将文件下载到请求它的客户端。

I completely misunderstood about using PHP-FTP to serve files to the clients Hard Drive. 我完全误解了有关使用PHP-FTP将文件提供给客户端硬盘的信息。

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). (这是一个音乐下载站点)。

You have a fundamental misunderstanding here: the "remote file" in an FTP connection is something remote from you - a file on another server somewhere, for instance. 您在这里有一个基本的误解:FTP连接中的“远程文件”是远离您的东西-例如,某处在另一台服务器上的文件。 In your case, I think the file you're trying to serve is "local" in this sense, but you want a way of getting it to a client quicker. 就您而言,我认为您要提供的文件在这种意义上是“本地”的,但是您想要一种更快地将其提供给客户的方法。

There is no way of pushing a file out to a client's hard drive (think of the security implications), you can only make it available . 无法将文件推送到客户端的硬盘驱动器(考虑到安全隐患),您只能使其可用 Right now, the client can request it using HTTP, and Apache will give them the content. 现在,客户端可以使用HTTP请求它,而Apache将为其提供内容。 If you installed an FTP server, they could connect with an FTP client and request it that way. 如果安装了FTP服务器,他们可以与FTP客户端连接并以这种方式请求它。 Similarly, you could install a different web server, like nginx or lighttpd, which might be faster. 同样,您可以安装其他Web服务器,例如nginx或lighttpd,它可能会更快。

Nothing you do in PHP, however, will be faster than just Apache, because you still have Apache involved, but now you have your PHP code as well, which at best requires the time to execute your code, before doing what Apache was going to do anyway. 但是,用PHP进行的所有操作都不会比仅Apache快,因为您仍然需要Apache的参与,但是现在您也有了PHP代码,这在执行Apache要做的事情之前最多需要时间来执行代码。反正做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM