FTP サーバーにログインし、抑制データの csv ファイルをダウンロードし、それを現在の抑制リスト ファイルとマージするために作成した PHP スクリプトがあります。
コマンドラインから実行すると完全に機能します。crontab で 1 日 1 回実行するように設定すると、常に FTP サーバーからファイルをダウンロードできないと表示されて終了します。スクリプトがファイルを書き込んでいるディレクトリに 777 を与えたので、それがパーミッションの問題になるとは思えません。
他の誰かがこの問題を抱えていますか? 私が見逃している簡単なものはありますか?以下は、私のcrontab行とスクリプトコードです。それが答えを与えるのに役立つ場合. ありがとうございました!
Crontab エントリ:
0 8 * * * php /var/www/scripts/ftp-unsubs.php >> /var/www/scripts/logs/ftp-unsubs.log
PHP スクリプト:
<?
// get latest suppression file and append to 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 up basic connection
$conn_id = ftp_connect($ftp_server);
// login with username and 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 to connect to $ftp_server for user $ftp_user_name\n";
exit;
} else {
echo "Connected to $ftp_server, for user $ftp_user_name\n";
}
// try to download $remote_file and save to $local_file
if (ftp_get($conn_id, $local_file, $remote_file, FTP_BINARY)) {
echo "Successfully written to $local_file\n";
} else {
echo "Couldn't get file $remote_file\n";
}
// close the FTP stream
if (ftp_close($conn_id)) {
print "Closed the connection to $ftp_server\n";
}
// grab new unsubs and 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 to global unsub file
$fsupp = fopen('loader.txt','a');
fwrite($fsupp, $unsub);
fclose($fsupp);
print "Added $i unsubs to loader.txt\n\n";
} else {
print "Error: file '$local_file' doesn't exist! Bailing.\n\n";
}
?>