Im confused by an estate agency vebra import script that worked fine before it was moved to a different server however now this seems to not work at all.
Does anyone have any idea why i would get the following warnings...
Warning: ftp_get() [function.ftp-get]: Opening data channel for file transfer. in /home/username/public_html/includes/cron/import/vebra-import.php on line 37
Warning: ftp_get() [function.ftp-get]: Transfer OK in /home/username/public_html/includes/cron/import/vebra-import.php on line 37
here is the ftp connection code:
$ftp = ftp_connect($ftp_host, 21) or die("FTP Connection Error");
ftp_login($ftp, $ftp_user, $ftp_pass) or die("Can't Connect to FTP");
$ftpdir = ftp_nlist($ftp, "/");
if(!empty($ftpdir) && count($ftpdir) > 0) {
foreach($ftpdir as $ftpfile) {
if(preg_match("/\.txt$/", $ftpfile)) {
$getfile = ftp_get($ftp, $csv_dir.$ftpfile, $ftpfile, FTP_BINARY);
if($getfile){
$downloaded++;
}
$total++;
}
}
}
ftp_close($ftp);
Furthermore, it seems to be intermittent, and sometimes this executes successfully other times it fails with the above errors.
Your server is not in a passive mode, and add this code to process:
ftp_pasv($ftp, true);
For more information look at passive mode on php.net: http://php.net/manual/en/function.ftp-pasv.php Passive mode uses the data initiated by the client rather than the server. So this is why you can't put on server. If this is not set it will fail.
NOTE: Set ftp_pasv()
function after ftp_login()
function.
After using ftp_pasv () the problem was still occurring. I found out that the number of requests to the server caused a problem with the firewall (I used a foreach() loop to scroll through multiple files). Because I did not have permission to modify the firewall rules, I added a sleep () in my script between the requests.
This is how i fixed the warning.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With