PHP ftp_nb_fget()Functions
Complete PHP FTP Reference Manual
Definition and Usage
The ftp_nb_fget() function downloads a file from an FTP server and saves it to a local already opened file. (Non-blocking)
This function returns one of the following values:
- FTP_FAILED (sending/fetching failed)
- FTP_FINISHED (sending/fetching succeeded)
- FTP_MOREDATA (sending/fetching is in progress)
Unlike ftp_fget(), this function fetches the file asynchronously. This means your program can perform other operations while the file is downloading.
Syntax
ftp_nb_fget(ftp_connection,local,remote,mode,resume)
| Parameters | Description |
|---|---|
| ftp_connection | Required. Specifies the FTP connection to use. |
| local | Required. Specifies a local open file to save the content to. |
| remote | Required. Specifies the path of the file to copy content from. |
| mode | Required. Specifies the transfer mode. Possible values:
|
| resume | Optional. Specifies where to start copying in the remote file. Default is 0. |
Examples
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_nb_fget($conn,$target,$source,FTP_ASCII);
ftp_close($conn);
?>
$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_nb_fget($conn,$target,$source,FTP_ASCII);
ftp_close($conn);
?>
Complete PHP FTP Reference Manual Other Extensions