PHP ftp_nb_get()Functions


PHP FTP 参考手册Complete PHP FTP Reference Manual

Definition and Usage

The ftp_nb_get() function downloads a file from the FTP server and saves it to a local file. (Non-blocking)

This function returns one of the following values:

  • FTP_FAILED (sending/getting failed)
  • FTP_FINISHED (sending/getting successful)
  • FTP_MOREDATA (sending/getting in progress)

Unlike ftp_get(), this function fetches the file asynchronously. This means your program can perform other operations while the file is being downloaded.

Syntax

ftp_nb_get(ftp_connection,local,remote,mode,resume)

Parameters Description
ftp_connection Required. Specifies the FTP connection to use.
local Required. Specifies a local file to save the content to. If the file already exists, it will be overwritten.
remote Required. Specifies the path of the file from which to copy content.
mode Required. Specifies the transfer mode. Possible values:
  • FTP_ASCII
  • FTP_BINARY
resume Optional. Specifies where in the remote file to start copying. Default is 0.


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");

ftp_nb_get($conn,"target.txt","source.txt",FTP_ASCII);

ftp_close($conn);
?>


PHP FTP 参考手册Complete PHP FTP Reference Manual Other Extensions