2 回答

TA貢獻1798條經(jīng)驗 獲得超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條經(jīng)驗 獲得超3個贊
根據(jù)代碼的工作方式,最簡單的解決方案是在調(diào)用之前將當前本地工作目錄更改為目標路徑ftp_sync:
chdir("/Users/John/Site/Code/PDF/");
ftp_sync (".");
- 2 回答
- 0 關注
- 182 瀏覽
添加回答
舉報