简体   繁体   English

PHP:ftp_get()只能下载一次具有相同名称的文件

[英]PHP: ftp_get() can download file with same name only once

I'm having a strange problem using ftp_get() on one of the two identical instances. 我在两个相同实例之一上使用ftp_get()遇到一个奇怪的问题。 One is on localhost and another on an actual server. 一个在本地主机上,另一个在实际服务器上。 I'm using the following to download a file via FTP. 我正在使用以下内容通过FTP下载文件。 Both of the instances download from the same FTP servers with the same credentials and same paths. 两个实例均从具有相同凭据和相同路径的相同FTP服务器下载。

$result = ftp_get($connection, $downloadPath, $serverPath, FTP_BINARY);

    if ($result) {
        $successfulWrites[] = $downloadPath;    // file name only without path
    } else {
        // on second attempt to download file with same name, ftp_get() returns false
        // this is where I throw an exception in my code
}

On my localhost, I can download the same file over and over, and it doesn't matter what the file name on the FTP server is or where it's located. 在我的本地主机上,我可以一次又一次地下载相同的文件,而FTP服务器上的文件名或位置都无关紧要。

On second instance, which is identical to the localhost's (ie pulled from the same git repo) in terms of code, I can download a file once, but the same file cannot be downloaded again, and ftp_get() returns false. 在第二个实例上,就代码而言,它与本地主机的实例相同(即从相同的git repo中拉出),我可以下载一次文件,但是不能再次下载相同的文件,并且ftp_get()返回false。 If I change the name of the file on the FTP server, I can download it, but after that it won't work again. 如果我在FTP服务器上更改了文件名,则可以下载它,但此后将无法再使用。 ie ftp_get() will return false. ftp_get()将返回false。

I don't have access to the FTP server log. 我无权访问FTP服务器日志。 If it's available, I'm going to try to get it today from the host. 如果有的话,我今天将尝试从主机上获取。 But can anyone think of a reason this might be happening? 但是谁能想到这可能发生的原因? ftp_get() just returns true or false without any explanation, so I'm pretty stuck with this. ftp_get()只是返回true或false而没有任何解释,因此我对此非常ftp_get()

I'm using PHP 5.4, and I have no idea what the spec is of the FTP (regular FTP) server. 我使用的是PHP 5.4,我不知道FTP(常规FTP)服务器的规格是什么。

As discussed, it sounded like ftp_get was successfully obtaining the file and writing it locally. 如所讨论的,听起来ftp_get成功地获取了文件并将其写入本地。 I wonder whether due to a permissions problem, when it tries to write the file locally again, it fails. 我想知道是否由于权限问题而导致在尝试再次本地写入文件时失败。 Thus, the FTP channel itself is fine, and the problem is just local. 因此,FTP通道本身很好,问题仅在本地。

I'm somewhat surprised at this though, as I would imagine PHP would have raised a warning. 我对此感到有些惊讶,因为我可以想象PHP会发出警告。 Is your error_reporting set to allow this whilst you are debugging? 在调试时,是否将error_reporting设置为允许此操作?

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

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