PHP ftp_fget() Function

Definition and Usage

The ftp_fget() function downloads a file from the FTP server and saves it to a locally opened file.

Returns true if successful, false otherwise.

Syntax

ftp_fget(ftp_connection,local,remote,mode,resume)
Parameter Description
ftp_connection Required. Specifies the FTP connection to be used (identifier of the FTP connection).
local Required. Handle of the locally opened 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
$source = "source.txt";
$target = fopen("target.txt", "w");
$conn = ftp_connect("ftp.testftp.com") or die("Could not connect");
ftp_login($conn,"admin","ert456");
ftp_fget($conn,$target,$source,FTP_ASCII);
ftp_close($conn);
?>