The ftp_get() function is an inbuilt function in PHP which is used to get or download files from FTP server to local server or machine.
ftp_get( $ftp_connection, $local_file_path, $server_file_path, $mode_of_file_transfer, $starting_position );
Parameters: This function accepts five parameters as mentioned above and described below:
- $ftp_connection: It is required parameter. It specifies the already existing FTP connection to use for downloading the file from the FTP server.
- $local_file_path: It is required parameter. It specifies the path of local server or machine to which the file is being downloaded.
- $server_file_path: It is required parameter. It specifies path of the file is to be downloaded from the FTP server.
- $mode_of_file_transfer: It is required parameter. It specifies the transfer mode. Values of the parameter is either FTP_ASCII or FTP_BINARY.
- $starting_position: It is an optional parameter. It specifies the position in the remote file to start downloading.
Return Value: It returns True on success or False on failure.
- 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 name.
- Mode should be chosen correctly i.e. either FTP_ASCII or FTP_BINARY
Vital information to run the following code: The following code will not work in online IDE as they don’t allow to interact with files. So try to run on PHP hosting server. Make sure provide correct FTP server, username, password, server file path, and local file path. If the file specifies as server file doesn’t exist then an error will occur so make sure server file exists. In these examples, the file mentioned as $server_file will be downloaded as local file to the relative path as provided in $local_file.
Below examples illustrate the ftp_get() function in PHP:
Example 2: Downloading of binary file from FTP Server.
- How to get the function name inside a function in PHP ?
- p5.js | nfs() Function
- PHP | each() Function
- D3.js | d3.min() function
- p5.js | nfp() Function
- p5.js | nfc() function
- p5.js | nf() Function
- CSS | rgb() Function
- PHP | Ds\Set first() Function
- PHP | Ds\Set contains() Function
- PHP | pi( ) Function
- p5.js | box() Function
- PHP Ds\Map sum() 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 email@example.com. 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.