FTP download file from server directly into client

前端 未结 3 815
你的背包
你的背包 2021-01-21 07:06

I try to download a file from FTP server into client. If I use ftp_get, the file is downloaded into PHP server, which can write the output into browser. So the down

3条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-21 07:53

    try below code for that.

    $curl = curl_init();
    $file = fopen("ls-lR.gz", 'w');
    curl_setopt($curl, CURLOPT_URL, "ftp://ftp.sunet.se/ls-lR.gz"); #input
    curl_setopt($curl, CURLOPT_FILE, $file); #output
    curl_setopt($curl, CURLOPT_USERPWD, "$_FTP[username]:$_FTP[password]");
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_exec($curl);
    

    Thanks.

提交回复
热议问题