The ftp_ssl_connect() function is an inbuilt function in PHP which opens a secure SSL-FTP connection. FTP functions can be run against the server while the connection is open. It opens an explicit SSL-FTP connection to the host specified in parameter. It will succeed even if the server’s certificate is invalid or is not configured for SSL-FTP.
Syntax:
ftp_ssl_connect($host, $port, $timeout);
Parameters: This function accepts three parameters as mentioned above and described below:
- $host: It is required parameter. It specifies the FTP server address. It can be a domain address or an IP address. This parameter shouldn’t be prefixed with “ftp://” or shouldn’t have any trailing slashes.
- $port: It is an optional parameter. It specifies the port to connect to. If no port is provided then default port is used i.e. 21.
- $timeout: It is also an optional parameter. It specifies the timeout for network operations. If not provided then default value is passed which is 90 seconds.
Return Value: It returns SSL-FTP stream on success or false on failure.
Note:
- This function is available on 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 name.
- This function is only available if both the ftp module and the OpenSSL support is built statically into PHP.
Below programs illustrate the ftp_ssl_connect() function in PHP:
Example 1:
<?php // Use ftp_ssl_connect() function to // check Connection $conn = ftp_ssl_connect("ftp.testftp.com") or die("Could not connect"); echo "Connection established successfully"; ?> |
Output:
Connection established successfully
Example 2: This example uses ftp_ssl_connect() function to logging in using SSL-FTP Connection
<?php // Setting up basic SSL connection // User IP address to which you // want to connect to $ftp_server = "8.8.8.8"; // Logging in in the established ftp connection. $ftp_conn = ftp_ssl_connect($ftp_server) or die("Could not connect to $ftp_server"); // Use your username $ftp_username = "your_username"; // Use your password $ftp_userpass = "your_password"; $login = ftp_login($ftp_conn, $ftp_username, $ftp_userpass); if( $login ) { echo "Successfully logged in with ".$ftp_server; } else { echo "Log in failed"; } // Closeing SSL connection ftp_close($ftp_conn); ?> |
Output:
Successfully logged in with 8.8.8.8
References: https://www.php.net/manual/en/function.ftp-ssl-connect.php
Recommended Posts:
- How to call a function that return another function in JavaScript ?
- How to Check a Function is a Generator Function or not using JavaScript ?
- How to get the function name from within that function using JavaScript ?
- How to get the function name inside a function in PHP ?
- D3.js | d3.mean() function
- PHP | exp() Function
- PHP | Ds\Set xor() Function
- p5.js | abs() function
- p5.js | red() function
- D3.js zip() Function
- PHP | Ds\Map get() Function
- D3.js | d3.sum() function
- p5.js | hue() function
- D3.js | d3.map.set() Function
- CSS | rgb() Function
- p5.js | sq() function
- p5.js | pow() function
- p5.js | min() function
- CSS env() Function
- p5.js | day() function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

