ASPit - Totally ASP JSit - Totally JavaScript
Search PHPit

Use this textbox to search for articles on PHPit. Seperate keywords with a space.

Advertisements

FTP Upload

This codesnippet can be used to login into a FTP server, and then upload a file. Common use might be for backup purposes on a off-site FTP server.

// Open FTP 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 the connection
if ((!$conn_id) || (!$login_result)) {
        echo 
"FTP connection has failed!";
        echo 
"Attempted to connect to $ftp_server for user $ftp_user_name";
        exit;
    } else {
        echo 
"Connected to $ftp_server, for user $ftp_user_name";
    }

// Upload the file
$upload ftp_put($conn_id$destination_file$source_fileFTP_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 connection
ftp_close($conn_id);
?>  

2 Responses to “FTP Upload”

  1. Nino Says:

    Copied from php.net ?

  2. ragnar Says:

    yep, kinda sure he did….

Leave a Reply