Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
ftp_fget() function in PHP
The ftp_fget() function is used to downloads file from the FTP server and save it into an open local file
Syntax
ftp_fget(con,open_file,server_file,mode,startpos);
Parameters
con − The FTP connection
open_file − A file where the data is stored
server_file − The server file to download
mode − The transfer mode
startpos − The position to begin downloading from. Added in PHP 4.3.0.
Return
The ftp_fget() function returns TRUE on success and FALSE on failure.
Example
The following is an example wherein we will download server file “demo.txt” and save it to open local file “new.txt” −
<?php
$ftp_server="192.168.0.4";
$ftp_user="amit";
$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";
$file_pointer = fopen($local_file,"w");
if (ftp_fget($con, $file_pointer, $my_serverfile, FTP_ASCII, 0)) {
echo "Written to $local_file!";
} else {
echo "Error in downloading the $my_serverfile!";
}
ftp_close($con);
fclose($file_pointer);
?> Advertisements
