PHP ftp_get() Function

Definition and Usage

The ftp_get() function downloads a file from the FTP server.

Returns true if successful, false otherwise.

Syntax

ftp_get(ftp_connection,local,remote,mode,resume)
Parameter Description
ftp_connection Required. Specifies the FTP connection to use (identifier of the FTP connection).
local Required. Specifies the local file.
remote Required. Specifies the path of the file to be copied from.
mode

Required. Specifies the transfer mode. Possible values include:

  • FTP_ASCII
  • FTP_BINARY
resume Required. Specifies where to start copying in the remote file. The default is 0.

Description

Parameter resume Only for PHP 4.3.0 and above versions

Example

This example copies text from "source.txt" to "target.txt":

<?php
$conn = ftp_connect("ftp.testftp.com") or die("Could not connect");
ftp_login($conn,"admin","ert456");
echo ftp_get($conn,"target.txt","source.txt",FTP_ASCII);;
ftp_close($conn);
?>

Output:

1