PHP Manual
Prev |  | Next

# XXXIII. FTP functions

The functions in this extension implement client access to file servers speaking the File Transfer Protocol FTP as defined in http://www.faqs.org/rfcs/rfc959.html.

The following constants are defined when using the FTP module: `FTP_ASCII` and `FTP_BINARY`.

In order to use FTP functions with your PHP configuration, you should add the `--enable-ftp` option when installing PHP 4, and `--with-ftp` when using PHP 3.

Example 1. ftp() example
    <?php
    // set up basic connection
    $conn_id = ftp_connect("$ftp_server");

    // login with username and password
    $login_result = ftp_login($conn_id, "$ftp_user_name", "$ftp_user_pass");

    // check connection
    if ((!$conn_id) || (!$login_result)) {
            echo "Ftp connection has failed!";
            echo "Attempted to connect to $ftp_server for user $ftp_user_name";
            die;
        } else {
            echo "Connected to $ftp_server, for user $ftp_user_name";
        }

    // upload the file
    $upload = ftp_put($conn_id, "$destination_file", "$source_file", FTP_BINARY);

    // check upload status
    if (!$upload) {
            echo "Ftp upload has failed!";
        } else {
            echo "Uploaded $source_file to $ftp_server as $destination_file";
        }

    // close the FTP stream
    ftp_quit($conn_id);
    ?>

Prev | Home | Next
fribidi_log2vis | Up | ftp_connect