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 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, pass开发者_C百科word 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;
}
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.
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.
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.
it's possible that PHP doesn't have permissions to write to the 'lgw
' subdirectory.
What are the permissions on this directory?
精彩评论