I wrote a php script to download files and folders through FTP so that i can take backups with certain conditions. But, it's not downloading all files. It's downloading some images from our server. I cant understand what's wrong with other rest of the images. They're all small images of flags of all countries. They're same size. If i download from more root level, it downloads other files. But, it exactly stops from co.png file.
Here is the link (http://robi123.com/flags.zip) to download the image files I'm trying to download using PHP FTP.
I know this script may need other improvements or get stuck in other steps too when downloading other large files. I need help to fix this problem for now. What's my script not downloading the other images? The warning of php is attached with this question. I've one more idea to try executing RAW FTP commands. Ignore the code of RAW FTP command. But all the other methods (ftp_get, ftp_nb_get and ) of ftp download are stuck in same thing and same warning. But you can advise any way.
Here is my code:
<?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/");
?>