第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

PHP FTP - 下載特定目錄中的文件而不是根目錄

PHP FTP - 下載特定目錄中的文件而不是根目錄

PHP
繁星淼淼 2023-10-15 17:21:02
我在 /Users/John/Site/Code/pdfsync.php 有一個 php 腳本在我的腳本中,我連接到 FTP,并遞歸下載文件,但是它在 /Users/John/Site/ 創(chuàng)建文件夾并下載文件,但我似乎不知道如何獲取這些文件下載到特定位置。假設當我運行腳本時,我希望它創(chuàng)建一個 PDF 文件夾,因此所有文件都在 /Users/John/Site/Code/PDF/ 下載,不知道如何實現(xiàn)這一點。$ftp_server = 'test.fr';$ftp_user_name = 'test';$ftp_user_pass = 'test';$server = 'test.fr';// set up basic connection$conn_id = ftp_connect($ftp_server);// login with username and password$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);if ((!$conn_id) || (!$login_result))    die("FTP Connection Failed");ftp_sync (".");echo "Done";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 ("..");}
查看完整描述

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;

}


查看完整回答
反對 回復 2023-10-15
?
倚天杖

TA貢獻1828條經(jīng)驗 獲得超3個贊

根據(jù)代碼的工作方式,最簡單的解決方案是在調(diào)用之前將當前本地工作目錄更改為目標路徑ftp_sync:


chdir("/Users/John/Site/Code/PDF/");

ftp_sync (".");


查看完整回答
反對 回復 2023-10-15
  • 2 回答
  • 0 關注
  • 182 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號