【问题标题】:ftp_fget(): Server cannot accept argument for random readftp_fget():服务器不能接受随机读取的参数
【发布时间】:2014-03-13 21:57:51
【问题描述】:

我正在使用 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 秒。

可能出了什么问题?

谢谢。

【问题讨论】:

  • 你能通过pastebin或其他东西附上完整的代码吗?我可以连接到我的 ftp 服务器并尝试重新生成相同的问题。

标签: php iis ftp


【解决方案1】:

我快速浏览了PHP FTP extension source code over at github。我没有找到那个字符串。这让我相信消息不是来自 PHP 本身,而是来自 FTP 服务器。

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-26
    • 1970-01-01
    • 2017-12-16
    • 2014-10-04
    相关资源
    最近更新 更多