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 ?
- PHP 5 vs PHP 7
- PHP | Get PHP configuration information using phpinfo()
- PHP | php.ini File Configuration
- How to import config.php file in a PHP script ?
- PHP | imagecreatetruecolor() Function
- PHP | fpassthru( ) Function
- PHP | ImagickDraw getTextAlignment() Function
- PHP | Ds\Sequence last() Function
- PHP | Imagick floodFillPaintImage() Function
- Function to escape regex patterns before applied in PHP
- PHP | array_udiff_uassoc() Function
- PHP | geoip_continent_code_by_name() Function
- PHP | GmagickPixel setcolor() function
- PHP | opendir() Function
- PHP | cal_to_jd() Function
- PHP | stream_get_transports() Function
- PHP | Ds\Deque pop() Function
- PHP | SimpleXMLElement children() Function
- PHP | array_intersect_ukey() 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.