警告:ftp_get():删除操作成功

时间:2013-09-26 16:48:05

标签: php ftp

我有一些代码可以从我们的开发服务器传输备份,并且它随机地表现得非常奇怪并且会产生以下错误/输出:

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

我一点也不知道删除与ftp_get()有什么关系,或者为什么它会返回false并抛出有关其他操作成功的警告。谷歌也没有发现任何类似的问题。

有问题的代码:

// 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);
    }
}

1 个答案:

答案 0 :(得分:7)

在我看来,你会遇到一个奇怪的PHP错误。

Delete operation successful.不是PHP错误消息,它是成功删除(DELE)命令的FTP服务器响应消息。

在对PHP源代码进行分析之后,我能找到的唯一解释是ftp_get函数失败而没有从FTP服务器收到错误消息,因此它显示的是FTP服务器响应上一个执行的命令,在这种特定情况下,是一个删除命令。

PHP FTP函数将FTP服务器响应文本存储在ftpbuf结构的inbuf field中:

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

然后在ftp_get function中使用此字段来显示警告消息:

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;
}

ftp->inbuf字段由ftp_getresp fnc写入,但可能是因为某些不明原因,低级别ftp_get function在未调用ftp_getresp函数的情况下失败因此显示误导性的错误信息 也许FTP服务器错误日志可以提供一些关于真正问题的线索,但没有进一步的信息真的很难说为什么你遇到了这个问题,甚至提出了一个解决方法。

我唯一的建议是针对不同的FTP服务器测试您的代码(如果可能),然后最终将您的PHP升级到更新的版本。