Speed up development with full-stack environments for every branch.

Learn More

How to login to ftp with ftp_login()

333 Runs 2886 Views 1097 Copies


gtsolutions 373

published 4 years ago


 * PHP ftp module
 * Login to a ftp with ftp_login()

// set up the url for the connection
$ftp_server = "ftp.bls.gov";
//connect to the server
$conn_id = ftp_connect($ftp_server);

// login with username and password (if you want to use anonymous connection 
//use the username: anonymous and leave the password field empty)
$ftp_user_name = "anonymous";
$ftp_user_pass = "";
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// check connection
echo "<center>";
if ((!$conn_id) || (!$login_result)) {
    echo '<div style="background-color:red;padding:10px;color:#fff;font-size:16px;">';
        echo "FTP connection has failed!";
        echo "Attempted to connect to <b>$ftp_server</b> for user <b>$ftp_user_name</b>";
    echo '</div>';
} else {
    echo '<div style="background-color:green;padding:10px;color:#fff;font-size:16px">';
        echo "Connected to <b>$ftp_server</b>, for user <b>$ftp_user_name</b>";
    echo '</div>';
echo "</center>";

// close the FTP stream 
Please login/signup to get access to the terminal.

Your session has timed out.

Dismiss (the page may not function properly).