Yet another recursive ftp_put.
* The parameters are similar to that of ftp_put, so if you need to copy a directory, just use ftp_put_dir(...) instead of ftp_put(...).
* Another advantage is that the remote directory doesn't need to exist.
* Returns TRUE on success, FALSE on failure.
* Inspired by lucas at rufy dot com and webmaster at sweetphp dot com.
<?php
function ftp_put_dir($ftp, $remote_dirname, $local_dirname, $mode=FTP_BINARY) {
    $success = true;
    if (!ftp_nlist($ftp, $remote_dirname)) {
        if (ftp_mkdir($ftp, $remote_dirname) === false) {
            $success = false;
        }
    }
    $dir = dir($local_dirname);
    while ($f = $dir->read()) {
        if ($f === '.' || $f === '..') {
            continue;
        }
        $lf = $local_dirname . '/' . $f;
        $rf = $remote_dirname . '/' . $f;
        if (is_dir($lf)) {
            if (!ftp_put_dir($ftp, $rf, $lf, $mode)) {
                $success = false;
            }
        } else {
            if (!ftp_put($ftp, $rf, $lf, $mode)) {
                $success = false;
            }
        }
    }
    $dir->close();
    return $success;
}
?>