I'm trying to build a script that will connect to my servers and download files for backup. I'm using the following code:
//*****FTP BACKUP PORTION*****\\
$curr_date = date("Y-m-d");
echo "<br>".$curr_date."<br>";
$backup_dir = "/backup";
mkdir($backup_dir."/temp/");
mkdir($backup_dir."/".$curr_date);
$ftp_mode = FTP_BINARY; //either FTP_BINARY or FTP_ASCII
$directory_list = Array();
// set up basic connection
$ftp_connection = ftp_connect($ftp_host);
// login with username and password
$login_result = ftp_login($ftp_connection, $ftp_username, $ftp_password);
// check connection
if ((!$ftp_connection) || (!$login_result)){
echo "FTP connection has failed!<BR>\n";
echo "Attempted to connect to ".$ftp_host." for user ".$ftp_username.".<BR>\n";
}
else {
echo "Connected to $ftp_host, for user $ftp_username";
}
echo "PWD: " . ftp_pwd($ftp_connection) . "<BR>\n";
//try to change the directory to defalut $ftp_start_dir
if (ftp_chdir($ftp_connection, $ftp_start_dir)) {
$curr_dir = ftp_pwd($ftp_connection);
echo "Current directory is now: ".$curr_dir."<BR>\n";
array_push($directory_list, $curr_dir);
}
else {
echo "Couldn't change directory to ".$ftp_start_dir." on remote server.<BR>\n";
}
for($j = 0; ISSET($directory_list[$j]); $j++){
if (ftp_chdir($ftp_connection, $directory_list[$j])) {
$curr_dir = ftp_pwd($ftp_connection);
echo "Current directory is now: ".$curr_dir."<BR>\n";
}
else {
echo "Could not change directory to: ".$directory_list[$j];
}
$curr_file_list = ftp_nlist($ftp_connection, ".");
$curr_dir = $directory_list[$j];
echo "<br><br><Br>";
var_dump($curr_file_list);
I get the following output:
Running backup for site boscoandcourtneydotcom
2007-06-03
Connected to ftp.boscoandcourtney.com, for user boscoandcourtneyPWD: /
Current directory is now: /httpdocs/img/icons
Current directory is now: /httpdocs/img/icons
bool(false)
Why would var_dump() produce bool(false) when I know there are files in that directory? Thanks for any help!