所以我得到了这段代码,它假设从远程主机上的 /upload/ 文件夹中获取所有内容并将其复制到文件所在的位置。代码如下所示:
<?php
$ftp_server = "server";
$conn_id = ftp_connect ($ftp_server)
or die("Couldn't connect to $ftp_server");
$login_result = ftp_login($conn_id, "user", "password");
if ((!$conn_id) || (!$login_result))
die("FTP Connection Failed");
ftp_sync ("/update/");
ftp_close($conn_id);
function ftp_sync ($dir) {
global $conn_id;
if ($dir != ".") {
if (ftp_chdir($conn_id, $dir) == false) {
echo ("Change Dir Failed: $dir<BR>\r\n");
return;
}
if (!(is_dir($dir)))
mkdir($dir);
chdir ($dir);
}
$contents = ftp_nlist($conn_id, ".");
foreach ($contents as $file) {
if ($file == '.' || $file == '..')
continue;
if (@ftp_chdir($conn_id, $file)) {
ftp_chdir ($conn_id, "..");
ftp_sync ($file);
}
else
ftp_get($conn_id, $file, $file, FTP_BINARY);
}
ftp_chdir ($conn_id, "..");
chdir ("..");
}
?>
当我在一个空文件夹中运行它时,它会做它应该做的事情。但是,如果我在包含 /update/ 文件的文件夹中运行它,它会给我两个错误。下面列出了错误
Warning: mkdir() [function.mkdir]: Permission denied in /home/limited/public_html/download.php on line 25
Warning: chdir() [function.chdir]: No such file or directory (errno 2) in /home/limited/public_html/download.php on line 26
假设只是用新文件覆盖文件,而不是抛出错误。
谢谢