Hi, there is a script that I'm trying to use for getting all the files of a remote directory and moving them to a directory on my local server (where the script runs from). I'm doing this so non-technical library staff can put images into our public server, then the script will "slurp" them up to our private archive server for indexing and display.
I was hoping someone could point out how to use it ... ie, it's not working correctly when I put it online and I'm not sure why.
Here's the script, I'm just running it as-is:
<?
/****************************************************************************
This code v1.0 is Copyright 2003 by Jon Bohren and Waveforme Backend Technologies
jon@waveforme.com
This function, ftp_dget(), willl download a directory and all it's contents.
You can choose to download sub directories or not by passing TRUE or FALSE
into $subd.
Feel free to use or edit this code, but please keep the copyright. Thanks!
Enjoy.
*****************************************************************************/
$ftp_host = "test.myserver.edu";
$ftp_user = "user";
$ftp_pass = "password";
$dir_name_server =".";
function ftp_dget($conn_id, $dir_name_local, $dir_name_server, $subd, $mode) {
//get file list for directory to be downloaded
$ls_dir = ftp_rawlist($conn_id, $dir_name_server);
//create local directory
if(!file_exists($dir_name_local))
$new_dir = mkdir($dir_name_local, 0777);
$curr_dir = chdir($dir_name_local);
//get rid of sub directories in file array if $subd is FALSE
if(!$subd) {
$s = 0;
for($i = 0; $i < sizeof($ls_dir); $i++) {
if($ls_dir[$i][0] != 'd') {
$ls_wsd[$s] = $ls_dir[$i];
$s++;
}
}
$ls_dir = $ls_wsd;
}
//download all files in the current directory, recursively call ftrp_dget() to downlaod sub-directories
for($i = 0; $i < sizeof($ls_dir); $i++) {
$curr_f_name = substr($ls_dir[$i], 55); //get actual file name
if($subd && ($ls_dir[$i][0] == 'd')) {
$dir_dl = ftp_dget($conn_id, $curr_f_name, $dir_name_server."/".$curr_f_name, $subd, $mode)or die("Couldn't download '".$curr_f_name."' via FTP"); //recursively call ftp_dget
} else {
$file_dl = ftp_get($conn_id, $curr_f_name, $dir_name_server."/".$curr_f_name, $mode)or die("Couldn't download '".$curr_f_name."' via FTP"); //call ftp_get to downlaod the files in the current dir
}
if(!($file_dl || $dir_dl))
return FALSE;
}
//return to previous directory
chdir("..");
return TRUE;
}
$conn_id = ftp_connect($ftp_host) or die("Couldn't connect to '".$ftp_host."'");
ftp_login($conn_id, $ftp_user, $ftp_pass) or die("Couldn't connect to the FTP server as '".$ftp_user."'");
ftp_dget($conn_id, $local_dir, $remote_dir, $downlaod_sub_directories, $mode);
?>
I get the errors
Warning: mkdir(): No such file or directory in /www/dept/php/test/test.php on line 25
Warning: chdir(): No such file or directory (errno 2) in /www/dept/php/test/test.php on line 26
Warning: ftp_get(): Error opening in /www/dept/php/test/test.php on line 47
Couldn't download '' via FTP
Any help would be greatly appreciated.