Return to Snippet

Revision: 30322
at August 11, 2010 23:13 by BrunoDeBarros


Initial Code
function ftp_download($ftp_host, $ftp_user, $ftp_pass, $remote_file_path, $local_file_path, $passive = true, $mode = FTP_BINARY) {

    $conn_id = ftp_connect($ftp_host);
    
    if ($conn_id) {

    if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) {
    
    ftp_pasv($conn_id, $passive);

    if (ftp_get($conn_id, $local_file_path, $remote_file_path, $mode)) {
        ftp_close($conn_id);
        return true;
    } else {
        ftp_close($conn_id);
        return false;
    }
    
    } else {
      throw new Exception("Failed to login to the FTP server.", 100)
    }
    
    } else {
      throw new Exception("Failed to connect to the FTP server.", 99);
    }
    
}

Initial URL


Initial Description
I wrote this code for when I need to get files from other servers and put them on my own server. I wanted to simplify it as much as possible.

Initial Title
Download a file from an FTP server and save it in a local file.

Initial Tags
download

Initial Language
PHP