Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Discussion on download file from ftp using curl

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 457
    Comment on it

    Hi Reader's,
    Welcome to FindNerd, today we are going to discuss on download file from FTP using curl.

    If you want to download files from FTP using curl then you have to follow below code.


    Suppose you want to download  "filename.xy" file which URL is given below :

    ftp://ftp.example.com/filename.xy

     

    Now you have to write below code :

    <?php 
        $curl = curl_init();
        $file = fopen("filename.gz", 'w');
        curl_setopt($curl, CURLOPT_URL, "ftp://ftp.example.com/filename.xy"); #input
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl, CURLOPT_FILE, $file); #output
        curl_setopt($curl, CURLOPT_USERPWD, "$_FTP[username]:$_FTP[password]");
        curl_exec($curl);
        curl_close($curl);
        fclose($file);
    
    ?>

    In above code you can replace filename.xy from your file name and also replace the FTP url with your FTP url.

    I hope this blog help to you download files from FTP using curl.

    Thanks

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: