Change language

PHP ftp_login () function

| |
Syntax:
ftp_login ($ftp_connection, $ftp_username, $ftp_userpass); 
Parameter:this function takes three parameters as above and described below:
  • $ftp_connection:required. It specifies the FTP connection to log in.
  • $ftp_username:Required. Specifies the username for the FTP connection.
  • $ftp_userpass:Required. It specifies the password for the user of this FTP connection.
Return Value:Returns True on success or False on failure.Notes:
  • This function is available for PHP 4.0.0 and newer.
  • The following examples cannot be run in the online IDE. So try running the correct ftp server hostname, username, password on some PHP hosting server or localhost.
The following programs illustrate the ftp_login() function in PHP: Example 1:  
// Connect to the FTP server $ftp_server = "localhost" ;  
// Use FTP username $ftp_username = "user" ;  
// Use FTP password $ftp_userpass = "user" ;  
// Establish FTP connection $ftp_connection = ftp_connect ( $ftp_server ) or die ( "Could not connect to $ftp_server" ); if ( $ftp_connection ) { echo "Successfully connected to the ftp server!" ; // login to the established connection // ftp user password $login = ftp_login ( $ftp_connection , $ftp_username , $ftp_userpass ); if ( $login ) { echo "
Logged in successfully!"
; } else { echo "
Login failed!"
; } // Close connection ftp_close ( $ftp_connection ) ; }  
?>
Output:
Successfully connected to the ftp server! Logged in successfully! 
Example 2.Connecting to ftp server on port 21.  
// Connect to the FTP server $ftp_server = "localhost" ;  
// Use FTP username $ftp_username = "user" ;  
// Use FTP password $ftp_userpass = "user" ;  
// Establish FTP connection $ftp_connection = ftp_connect ( $ftp_server , 21) or die ( "Could not connect to $ftp_server" ); if ( $ftp_connection ) { echo "Successfully connected to the ftp server!" ; // login to the established connection // ftp user password $login = ftp_login ( $ftp_connection , $ftp_username , $ftp_userpass ); if ( $login ) { echo "
Logged in successfully!"
; } else { echo "
Login failed!"
; } // Close connection ftp_close ( $ftp_connection ) ; }  
?>
Output:
Successfully connected to the ftp server! Logged in successfully! 
Link: https://www.php. net / manual / en / function.ftp-login.php
SO 1 data error