【发布时间】: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 服务器并尝试重新生成相同的问题。