ftp_fget():服务器不能接受随机读取的参数


ftp_fget(): Server cannot accept argument for random read

我正在使用ftp_connect和ftp_login连接FTP。

    $this->connID = ftp_connect($this->host, 21, static::FTP_TIMEOUT);
    if (!$this->connID) {
        throw new 'Exception('Connection to FTP: '. $this->host .' failed.');
    }       
    $loginResult = ftp_login($this->connID, $this->username, $this->password);
    if(!$loginResult) {
        throw new 'Exception('Auth for FTP user ' .$this->username. ' failed.');
    }

之后,我使用下面的命令集检查DIR是否存在。

    $resultPwd = ftp_pwd($this->connID);
    if ($resultPwd===false) {
        throw new 'Exception ('Command ftp_pwd failed.');
    }
    $resultChdir = ftp_chdir($this->connID, $this->filesDir);
    if ($resultChdir===false) {
        throw new 'Exception ('ftp_chdir failed, its most likely that directory: ' .$this->filesDir . ' does not exists');
    }
    $resultChdirBack = ftp_chdir($this->connID, $resultPwd);
    if ($resultChdirBack===false) {
        throw new 'Exception ('Directory test failed, coult not set back directory to: '. $resultChdirBack);
    }

之后,我得到的文件列表(约200)与以下代码:

$arrFilePath= ftp_nlist($this->connID, $this->filesDir);

之后我遍历文件并读取它们:

$resultGet = ftp_fget($this->connID, $fhTemp, $remoteFilePath, FTP_ASCII);

问题是,在读取未知数量的文件ftp_fget失败后,我得到:

Warning: ftp_fget(): Server cannot accept argument.

我也尝试了每个文件迭代关闭连接并再次打开它,但是它没有解决问题。

我也试图建立被动连接,但我的FTP服务器似乎不能正确地使用被动模式,因为每一个命令切换到被动模式后失败。

我还把超时时间增加到15秒。

怎么了?

谢谢。

我在github上快速查看了PHP FTP扩展的源代码。我没找到那根绳子。这让我相信这个消息不是来自PHP本身,而是来自FTP服务器。

我建议您在FTP服务器部分启用日志记录来检查问题,或者在脚本运行时使用Wireshark或tcpdump查看实际的网络流量。

您应该在问题中添加转储的摘录。如果你发现了问题并解决了它,请随意回答你自己的问题。