PHP | ftp_login() function Last Updated : 30 Oct, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report The ftp_login() function is an inbuilt function in PHP which is used to login to an established FTP connection. Syntax: ftp_login( $ftp_connection, $ftp_username, $ftp_userpass ); Parameter: This function accepts three parameters as mentioned above and described below: $ftp_connection: It is required parameter. It specifies the FTP connection to which to login. $ftp_username: It is required parameter. It specifies the username for the FTP Connection. $ftp_userpass: It is required parameter. It specifies the password for the user of that FTP connection. Return Value: It returns True on success or False on failure. Note: This function is available for PHP 4.0.0 and newer version. The following examples cannot be run on online IDE. So try to run in some PHP hosting server or localhost with proper ftp server host name, username, password. Below programs illustrate the ftp_login() function in PHP: Example 1: php <?php // Connect to 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!"; // logging in to established connection with // ftp username password $login = ftp_login($ftp_connection, $ftp_username, $ftp_userpass); if($login) { echo "<br>Logged in successfully!"; } else { echo "<br>Login failed!"; } // Closing the connection ftp_close($ftp_connection); } ?> Output: Successfully connected to the ftp server! Logged in successfully! Example 2: Connect to ftp server using port 21. php <?php // Connect to 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!"; // logging in to established connection with // ftp username password $login = ftp_login($ftp_connection, $ftp_username, $ftp_userpass); if($login) { echo "<br>Logged in successfully!"; } else { echo "<br>Login failed!"; } // Closing the connection ftp_close($ftp_connection); } ?> Output: Successfully connected to the ftp server! Logged in successfully! Reference: https://www.php.net/manual/en/function.ftp-login.php Comment More infoAdvertise with us Next Article PHP | ftp_nlist() function G gekcho Follow Improve Article Tags : Web Technologies PHP PHP-function PHP- FTP Similar Reads PHP | ftp_nlist() function The ftp_nlist() function is an inbuilt function in PHP which is used to get the list of all the filename and sub-directory in a specific directory on FTP server. Syntax: ftp_nlist( $ftp_connection, $directory ); Parameters: This function accepts two parameters as mentioned above and described below 3 min read PHP | ftp_set_option() Function The ftp_set_option() function is an inbuilt function in PHP which is used to set runtime option for existing FTP Connection. Syntax: ftp_set_option( $ftp_connection, $option, $value ) Parameter: This function accepts three parameters as mentioned above and described below:  $ftp_connection: It is 2 min read PHP | ftp_mkdir() function The ftp_mkdir() function is an inbuilt function in PHP which is used to create a new directory on the ftp server. Once the directory is created cannot be created again. Creating a directory that already exists will produce error. Syntax: string ftp_mkdir( $ftp_connection, $directory_name ) Paramete 3 min read PHP | link( ) Function The link() creates a hard link for a specified target. The target and the link are passed as parameters to the link() function and it returns true on success and false on failure.Syntax: link(target, link)  Parameters Used: The link() function in PHP accepts two parameters. target : It is a manda 2 min read PHP | ftp_raw() function The ftp_raw() function is an inbuilt function in PHP which is used to send a raw command to the Remote server i.e. FTP Server. Syntax: ftp_raw( $ftp_connection, $command ) Parameters: This function accepts two parameters as mentioned above and described below:  $ftp_connection: It is required para 2 min read PHP | ftp_pwd() function The ftp_pwd() function is an inbuilt function in PHP which returns the current directory name of the specified FTP connection. This function was introduced in PHP 4. Syntax: string ftp_pwd( $ftp_conn ) Parameter: This function accepts single parameter $ftp_conn which is used to specify the used FTP 2 min read Like