Question

I'm having a strange problem using ftp_get() on one of the two identical instances. One is on localhost and another on an actual server. I'm using the following to download a file via FTP. Both of the instances download from the same FTP servers with the same credentials and same paths.

$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.

On second instance, which is identical to the localhost's (i.e. 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. If I change the name of the file on the FTP server, I can download it, but after that it won't work again. i.e. ftp_get() will return false.

I don't have access to the FTP server log. 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.

I'm using PHP 5.4, and I have no idea what the spec is of the FTP (regular FTP) server.

Was it helpful?

Solution

As discussed, it sounded like ftp_get was successfully obtaining the file and writing it locally. 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.

I'm somewhat surprised at this though, as I would imagine PHP would have raised a warning. Is your error_reporting set to allow this whilst you are debugging?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top