ftp_nb_get() function in PHP


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

Syntax

ftp_nb_get(con,local_file,server_file,transfer_mode,beg_pos);

Parameters

  • con − The FTP connection

  • local_file − The local file path

  • server_file − The server file to download

  • transfer_mode − This is the transfer mode. The following are the possible values −

    - FTP_ASCII, or

    - FTP_BINARY

  • beg_pos − The position to begin the downloading

Return

The ftp_nb_get() function returns any of the following values −

  • FTP_FAILED − send/receive failed

  • FTP_FINISHED − send/receive completed

  • FTP_MOREDATA − send/receive in progress

Example

The following is an example:

<?php
   $ftp_server = "192.168.0.4";
   $ftp_user = "jacob";
   $ftp_pass = "tywg61gh";
   $con = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
   $login = ftp_login($con, $ftp_user, $ftp_pass);
   $my_serverfile = "demo.txt";
   $local_file = "new.txt";
   $c = ftp_nb_get($con, $local_file , $my_serverfile, FTP_ASCII)
   while ($c == FTP_MOREDATA){
      // continue downloading
      $c = ftp_nb_continue($con);
   }
   if ($c != FTP_FINISHED) {
      echo "Error downloading the server file!";
      exit(1);
   }
   // close
   fclose($file_pointer)
?>

Updated on: 30-Jul-2019

34 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements