Warning: ftp_get(): Delete operation successful

2019-06-21 04:33发布

I've got a bit of code that transfers backups from our development servers, and it randomly seems to behave very strangely and giving the following errors/output:

Warning: ftp_get(): Delete operation successful. in /root/cron/get_dev_archives.php on line 106
ERR blahjob: Failed to get file: 2013-09-25_18-22-04-blahjob_dev18.tgz
PHP Warning:  ftp_get(): Delete operation successful. in /root/cron/get_dev_archives.php on line 106

Warning: ftp_get(): Delete operation successful. in /root/cron/get_dev_archives.php on line 106
ERR blahjob: Failed to get file: 2013-09-25_18-22-37-blahjob_dev19.tgz
PHP Warning:  ftp_get(): Delete operation successful. in /root/cron/get_dev_archives.php on line 106

Warning: ftp_get(): Delete operation successful. in /root/cron/get_dev_archives.php on line 106
ERR blahjob: Failed to get file: 2013-09-25_18-23-05-blahjob_dev5.tgz
PHP Warning:  ftp_get(): Delete operation successful. in /root/cron/get_dev_archives.php on line 106

Warning: ftp_get(): Delete operation successful. in /root/cron/get_dev_archives.php on line 106
ERR blahjob: Failed to get file: 2013-09-25_18-23-37-blahjob_dev33.tgz

I haven't the slightest idea what delete has to do with ftp_get(), or why it's returning false and throwing a warning about another operation's success. Google has also been unhelpful in finding any similar issues.

Code in question:

// ftp connection established, file list acquired, yadda yadda
foreach( $targets as $target ) {
    $localfile = $backup_dir . $target;
    if( file_exists($localfile) ) {
        do_log($task['name'], "Local file ".$target." already exists, skipping.", 1);
        continue;
    }
    if( ! ftp_get($conn, $localfile, $target, FTP_BINARY) ) { // line 106
        do_log($task['name'], "Failed to get file: ".$target, 2);
    } else {
        do_log($task['name'], "Got file: ".$target);
        ftp_delete($conn, $target);
    }
}

标签: php ftp
1条回答
相关推荐>>
2楼-- · 2019-06-21 04:49

In my opinion you are incurring in a strange PHP bug.

The Delete operation successful. is not a PHP error message, it's the FTP server response message for a successful delete (DELE) command.

After an analysis of the PHP source code, the only explanation I can find for this problem is that the ftp_get function is failing without getting an error message from the FTP server, therefore it's displaying the FTP server response of the previous executed command which, in this specific case, is a delete command.

The PHP FTP functions store the FTP server response text in the inbuf field of the ftpbuf structure:

typedef struct ftpbuf {
    ...
    char        inbuf[FTP_BUFSIZE]; /* last response text */
    ...
}

Such field is then used in the ftp_get function to display the warning message:

if (!ftp_get(ftp, outstream, remote, xtype, resumepos TSRMLS_CC)) {
    php_stream_close(outstream);
    VCWD_UNLINK(local);
    php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ftp->inbuf);
    RETURN_FALSE;
}

The ftp->inbuf field is written by the ftp_getresp fnc, but it may be that, for some obscure reason, the low level ftp_get function is failing without calling the ftp_getresp function, therefore showing a misleading error message.
Maybe the FTP server error logs could give some clues about what the real problem is, but without further informations is really difficult to say why you're experiencing this problem and even to propose a workaround.

My only suggestion is to test your code (if possible) against a different FTP server, then eventually upgrade your PHP to a newer version.

查看更多
登录 后发表回答