gpt4 book ai didi

php - 使用PHP通过FTP下载文件夹

转载 作者:可可西里 更新时间:2023-11-01 13:09:45 26 4
gpt4 key购买 nike

如何使用 FTP 和 PHP 从远程主机下载文件夹?

我有用户名和密码以及要下载的文件夹...copy()?

告诉我,谢谢!

最佳答案

<?php 
$ftp_server = "ftp.example.com";
$conn_id = ftp_connect ($ftp_server)
or die("Couldn't connect to $ftp_server");

$login_result = ftp_login($conn_id, "user", "pass");
if ((!$conn_id) || (!$login_result))
die("FTP Connection Failed");

ftp_sync ("DirectoryToCopy"); // Use "." if you are in the current directory

ftp_close($conn_id);

// ftp_sync - Copy directory and file structure
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 ("..");

}
?>

来源:https://www.php.net/manual/function.ftp-get.php#90910

关于php - 使用PHP通过FTP下载文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5650439/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com