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, 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;
}