download a file from ftp using curl and php

前端 未结 6 1634
伪装坚强ぢ
伪装坚强ぢ 2020-11-30 03:32

I\'m trying to download a file from an ftp server using curl and php but I can\'t find any documentation to help

$curl = curl_init();
curl_setopt($curl, CURL         


        
6条回答
  •  执念已碎
    2020-11-30 04:06

    $ftp_location = put your ftp adress here; 
    $location_login = put your login here;
    $location_pwd = put your password here;
    $conn_id = ftp_connect("$ftp_location");
    $login_result = ftp_login($conn_id, $location_login, $location_pwd);
    
    if ((!$conn_id) || (!$login_result)) {
        echo "FTP connection has failed!";
        exit;
    } else {
        echo "Connected";
    }
    
    // get the file
    // change products.csv to the file you want
    $local = fopen("products.csv","w");
    $result = ftp_fget($conn_id, $local,"products.csv", FTP_BINARY);
    fwrite($local, $result); fclose($local); 
    
    // check upload status
    if (!$result) {
        echo "FTP download has failed!";
    } else {
        echo "Downloaded ";    
    }
    
    // close the FTP stream
    ftp_close($conn_id);
    

提交回复
热议问题