在PHP中使用ftp_get()获取警告 [英] Getting warning on ftp_get() in PHP
问题描述
我尝试使用ftp_get()
检索文本文件,并在执行脚本时收到警告:
I try to retrieve a text file using ftp_get() and when I execute the script I get warning:
ftp_get() [function.ftp-get]: Can't open data connection
Can some一个给出一些线索有什么问题。这是我以前的托管/服务器,因为我把它打破了。是否有一些特定的PHP配置。我检查了phpinfo并启用了FTP支持。
连接获取资源ID,用户名,密码和ftp主机通过CuteFTP工作。
Can some one give some clue what is wrong. This was working on my previous hosting/server since I moved it it broke. Are there some specific PHP configurations. I checked the phpinfo and the FTP support is enabled. The connection got resource id and the username, password and ftp host work through CuteFTP.
function _getFtpFile( $fileName = '' ) {
if($fileName == '') {
return false;
}
$model = $this->getModel();
$params =& $model->getParams();
$vebraHost = $params->get('vebra_host');
$vebraUser = $params->get('vebra_username');
$vebraPass = $params->get('vebra_password');
$localFile = JPATH_BASE.'/tmp/tmp.csv';
// Delete the file in case it exists
@unlink($localFile);
// set up basic connection
$connId = ftp_connect($vebraHost);
// login with username and password
$loginResult = ftp_login($connId, $vebraUser, $vebraPass);
// turn on passive mode transfers
ftp_pasv($connId, true);
// try to download $server_file and save to $localFile
if (!ftp_get($connId, $localFile, $fileName, FTP_BINARY)) {
$file = false;
} else {
$file = $localFile;
}
// close the connection
ftp_close($connId);
return $file;
}
推荐答案
像FTP问题,而不是PHP问题,因为无法打开数据连接是一个FTP错误425,这是一个FTP协议级错误。有很多FTP服务器可能导致的问题,特别是错误配置的问题。
To be honest, this sounds like an FTP problem, not a PHP problem, as a "Can't open data connection" is an FTP error 425, which is a FTP protocol level error. There are plenty of problems that an FTP server can cause, especially one that is misconfigured.
如果我猜测,我会说问题在于配置FTP服务器,可能在主动/被动设置中,但可能在防火墙设置的某处。它也可能存在于你的,但似乎不太可能,因为你仍然可以通过CuteFTP连接。
If I were to guess, I would say the problem lies within the configuration of the FTP server, possibly in the active/passive settings, but probably somewhere in their firewall settings. It could also lie in yours, but that seems unlikely, as you can still connect via CuteFTP.
FTP服务器是远程服务器还是脚本托管在?如果它们相同,很可能会有港口冲突。我会联系您的主机的支持,看看他们是否认识到这是一个问题。
Is the FTP server a remote server, or is the same one that script is hosted on? It's very possible there could be port conflicts if they are the same. I would get in contact with your hosting's support, see if they recognize it as an issue.
这篇关于在PHP中使用ftp_get()获取警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!