WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

PHP ftp_nb_fget() function


Definition and usage

The ftp_nb_fget () function downloads a file from an FTP server and saves it to an open file locally. (Non-blocking)

This function returns one of the following values:

  • FTP_FAILED (send /get failed)
  • FTP_FINISHED (send /get successfully)
  • FTP_MOREDATA (Send /Get is in progress)

Unlike ftp_fget (), this function fetches a file asynchronously. This means that 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 an open file on the local computer where the content is to be saved.
remote Required. Specifies the path of the file from which content is copied.
mode Required. Specify the transmission mode. Possible values:
  • FTP_ASCII
  • FTP_BINARY
resume Optional. Specifies where in the remote file to start copying. The default is 0.


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_nb_fget($conn,$target,$source,FTP_ASCII);

ftp_close($conn);
?>