Crontab won't download file from FTP server using PHP -


i have php script i've written login ftp server, download csv file of suppression data, , merge our current suppression list file.

it works when run command line. when set run once day in crontab, says can't download file ftp server, , exits. i've given 777 directory script writing file to, can't imagine permissions problem.

has else had issue? there simple i'm missing? below crontab line , script code, if in giving answer. thank you!

crontab entry:

0 8 * * * php /var/www/scripts/ftp-unsubs.php >> /var/www/scripts/logs/ftp-unsubs.log

php script:

<? // latest suppression file , append our global suppression file (loader.txt)  $yesterday = date("y-m-d", strtotime("yesterday")); $ftp_server = '--hidden--'; $ftp_user_name = '--hidden--'; $ftp_user_pass = '--hidden--'; $local_file = 'unsub_dls/unsubs.' . $yesterday . '.csv'; $remote_file = 'fjm378_unsubs.' . $yesterday . '.csv';   // set basic connection $conn_id = ftp_connect($ftp_server);  // login username , password $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);  ftp_pasv($conn_id, true);  print "\n[" . date("r") . "]\n";  if ((!$conn_id) || (!$login_result)) {     echo "ftp connection has failed!\n";     echo "attempted connect $ftp_server user $ftp_user_name\n";     exit; } else {     echo "connected $ftp_server, user $ftp_user_name\n"; }  // try download $remote_file , save $local_file  if (ftp_get($conn_id, $local_file, $remote_file, ftp_binary)) {   echo "successfully written $local_file\n"; } else {   echo "couldn't file $remote_file\n"; }  // close ftp stream if (ftp_close($conn_id)) {   print "closed connection $ftp_server\n"; }   // grab new unsubs , add timestamp print "\nprocessing file $local_file\n";  if (file_exists($local_file)) {    $fh = fopen($local_file, 'r');    $i = 0;   $unsub = "";   while (!feof($fh)) {     $line = fgets($fh);     $line = preg_replace('/(?:(?:\r\n|\r|\n)\s*){2}/s', "", $line);     if ($line != "" && $line != "email") {       $unsub .= $line . "," . date("y-m-d h:i:s") . "\n";       $i++;     }   }    fclose($fh);    // add unsubs global unsub file   $fsupp = fopen('loader.txt','a');   fwrite($fsupp, $unsub);   fclose($fsupp);    print "added $i unsubs loader.txt\n\n";  } else {   print "error: file '$local_file' doesn't exist! bailing.\n\n"; } ?> 

try add username under credentials task should run crontab entry this:

0 8 * * * root php /var/www/scripts/ftp-unsubs.php >> /var/www/scripts/logs/ftp-unsubs.log


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -