Latest web development tutorials

PHP ftp_fget () function

PHP FTP Reference Complete PHP FTP Reference

Definition and Usage

ftp_fget () function to download a file from the FTP server and saves it to an open file.

If successful, the function returns TRUE. If it fails, it returns FALSE.

grammar

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

参数 描述
ftp_connection 必需。规定要使用的 FTP 连接。
local 必需。规定要保存内容的本地一个已经打开的文件。
remote 必需。规定从中复制内容的文件的路径。
mode 必需。规定传输模式。可能的值:
  • FTP_ASCII
  • FTP_BINARY
resume 可选。规定在远程文件中的何处开始复制。默认是 0。


Examples

This example is copied from the "source.txt" text to "target.txt" in:

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

ftp_close($conn);
?>


PHP FTP Reference Complete PHP FTP Reference