2 回答
TA贡献1798条经验 获得超7个赞
您可以使用这个库非常轻松地做到这一点:
代码 :
$connection = new FtpConnection('host', 'username', 'password');
$client = new FtpClient($connection);
if (asyncDownload('Users/John/Site/Code/PDF', '.')) {
echo 'Done!';
}
function syncDownload($localDir, $remoteDir)
{
global $client;
if (!is_dir($localDir)) {
mkdir($localDir);
}
/**
* listDirectoryDetails method will recursively gets all the files with
* their details within the giving directory.
*/
$files = $client->listDirectoryDetails($dir, true);
foreach($files as $file) {
$client->download($file['path'], $localDir . '/' . $file['name'], true, FtpWrapper::BINARY);
}
return true;
}
TA贡献1828条经验 获得超3个赞
根据代码的工作方式,最简单的解决方案是在调用之前将当前本地工作目录更改为目标路径ftp_sync:
chdir("/Users/John/Site/Code/PDF/");
ftp_sync (".");
- 2 回答
- 0 关注
- 133 浏览
添加回答
举报