特定の条件でバックアップを取ることができるように、FTP 経由でファイルとフォルダーをダウンロードするための php スクリプトを作成しました。ただし、すべてのファイルをダウンロードしているわけではありません。サーバーからいくつかの画像をダウンロードしています。残りの画像の何が問題なのか理解できません。それらはすべて、すべての国の国旗の小さな画像です。それらは同じサイズです。より多くのルートレベルからダウンロードすると、他のファイルがダウンロードされます。しかし、co.pngファイルからピタッと止まります。
PHP FTP を使用してダウンロードしようとしている画像ファイルをダウンロードするためのリンク( http://robi123.com/flags.zip ) を次に示します。
このスクリプトには、他の大きなファイルをダウンロードするときに、他の改善が必要であるか、他の手順でスタックする可能性があることを知っています。今のところ、この問題を解決するために助けが必要です。他の画像をダウンロードしないスクリプトは何ですか? この質問にはphpの警告が添付されています。RAW FTP コマンドを実行してみるというアイデアがもう 1 つあります。RAW FTP コマンドのコードを無視します。しかし、ftp ダウンロードの他のすべてのメソッド (ftp_get、ftp_nb_get、および ) は、同じことと同じ警告でスタックします。しかし、あなたはどんな方法でもアドバイスすることができます。
これが私のコードです:
<?php
set_time_limit(0);
ini_set('xdebug.max_nesting_level', "100000000000000000000000");
$ftp_server = "";
$ftp_user = "";
$ftp_pass = "";
$ftp_conn = ftp_connect($ftp_server);
$ftp_login = ftp_login($ftp_conn, $ftp_user, $ftp_pass);
ftp_set_option($ftp_conn, FTP_TIMEOUT_SEC, 10000000);
ftp_set_option($ftp_conn, FTP_AUTOSEEK, true);
ftp_pasv($ftp_conn, true);
if ((!$ftp_conn) || (!$ftp_login)) {
echo "FTP connection has failed!";
echo "Attempted to connect to $ftp_server for user $ftp_user<br />";
} else {
echo "Connected to $ftp_server, for user $ftp_user<br />";
}
echo getcwd()."<br />" ;
function download($ftp_conn,$local_folder,$remote_folder){
if($local_folder !=""){
chdir($local_folder);
}
echo getcwd()."<br />" ;
ftp_chdir($ftp_conn,$remote_folder);
$files_folders = ftp_nlist($ftp_conn, ".");
foreach($files_folders as $temp){
if ($temp == '.' OR $temp == '..'){
continue;
}
if(ftp_is_dir($ftp_conn,$temp)){
//echo "$temp<br>";
@mkdir($temp);
echo "Folder: ".$remote_folder."/".$temp."<br />";
download($ftp_conn,$temp,$remote_folder."/".$temp);
}else{
ftp_get($ftp_conn, $temp, $temp, FTP_BINARY);
//ftp_nb_get($ftp_conn, $temp, $temp, FTP_BINARY);
/*
$ret = ftp_nb_get($ftp_conn, $temp, $temp, FTP_BINARY);
while ($ret == FTP_MOREDATA) {
$ret = ftp_nb_continue($ftp_conn);
}
if ($ret != FTP_FINISHED) {
echo "There was an error downloading the file";
exit(1);
}
$command = "RETR $remote_folder/$temp";
$result = ftp_raw($ftp_conn, trim($command));
print_r($result);
*/
echo "File: $temp<br />";
}
}
chdir("..");
ftp_chdir($ftp_conn, "..");
return;
}
function ftp_is_dir($ftp_conn,$dir) {
if (@ftp_chdir($ftp_conn, $dir)) {
ftp_chdir($ftp_conn, '..');
return true;
} else {
return false;
}
}
download($ftp_conn,"data","/public_html/c4smod/traffic/Img/Flags/");
?>