function PMBP_save_FTP($files, $packed = false) { global $CONF; global $PMBP_SYS_VAR; $out = FALSE; // try to connect to server using username and passwort if (!$CONF['ftp_server']) { $out .= "<div class=\"red\">" . C_WRONG_FTP . "</div>"; } elseif (!($conn_id = @ftp_connect($CONF['ftp_server'], $CONF['ftp_port'], $PMBP_SYS_VAR['ftp_timeout']))) { $out .= "<div class=\"red\">" . F_FTP_1 . " '" . $CONF['ftp_server'] . "'!</div>"; } else { if (!($login_result = @ftp_login($conn_id, $CONF['ftp_user'], $CONF['ftp_passwd']))) { $out .= "<div class=\"red\">" . F_FTP_2 . " '" . $CONF['ftp_user'] . "'.</div>"; } else { // succesfully connected -> set passive and change to the right path if ($CONF['ftp_pasv']) { ftp_pasv($conn_id, TRUE); } else { ftp_pasv($conn_id, FALSE); } if (!$CONF['ftp_path']) { $path = "."; } else { $path = $CONF['ftp_path']; } @ftp_chdir($conn_id, $path); // backup as one ZIP file if ($packed) { include_once "pclzip.lib.php"; $filename = $CONF['sitename'] . "." . time() . ".zip"; $pclzip = new Pclzip(PMBP_EXPORT_DIR . $filename); $pclzip->create($files); // try three times to upload zip files $check = FALSE; for ($i = 0; $i < 3; $i++) { if (!$check) { $check = ftp_put($conn_id, $filename, PMBP_EXPORT_DIR . $filename, FTP_BINARY); } } if ($check) { // adjust file permissions on ftp server //ftp_chmod($conn_id,substr(sprintf('%o', fileperms(PMBP_EXPORT_DIR.$filename)), -4),$filename); $out .= "<div class=\"green\">" . F_FTP_4 . " '" . $filename . "'.</div>\n"; } else { $out .= "<div class=\"red\">" . F_FTP_3 . ".</div>\n"; } @unlink(PMBP_EXPORT_DIR . $filename); // backup each file } else { // create all missing folders foreach ($files as $filepath) { if ($filepath = trim($filepath)) { $folders = explode("/", $filepath); $filename = array_pop($folders); $deep = 0; $all_folders = ""; $all_folders_local = ""; foreach ($folders as $folder) { $all_folders_local .= $folder . "/"; if ($folder != "." && $folder != "..") { if (!@ftp_chdir($conn_id, $folder)) { @ftp_mkdir($conn_id, $folder); @ftp_chdir($conn_id, $folder); } // adjust directory permissions //ftp_chmod($conn_id,substr(sprintf('%o', fileperms("../".$folder)), -4),"../".$folder); $all_folders .= $folder . "/"; $deep++; } } // change back to $path $rel_path = ""; for ($i = 0; $i < $deep; $i++) { $rel_path .= "../"; } @ftp_chdir($conn_id, $rel_path); // define the source and destination pathes $dest_file = $all_folders . $filename; $source_file = "./" . $filepath; // try three times to upload $check = FALSE; for ($i = 0; $i < 3; $i++) { if (!$check) { $check = @ftp_put($conn_id, $dest_file, $source_file, FTP_BINARY); } } if ($check) { // adjust file permissions on ftp server //ftp_chmod($conn_id,substr(sprintf('%o', fileperms($source_file)), -4),$dest_file); $out .= "<div class=\"green\">" . F_FTP_4 . " '" . $dest_file . "'.</div>\n"; } else { $out .= "<div class=\"red\">" . F_FTP_3 . ": '" . $source_file . "' -> '" . $dest_file . "'.</div>\n"; } } } } // close the FTP connection if (@function_exists("ftp_close")) { @ftp_close($conn_id); } } } return $out; }