PHP ftp_fput() Function

Definition and Usage

The ftp_fput() function uploads an already opened file to the FTP server.

Returns true on success, false on failure.

Syntax

ftp_fput(ftp_connection,remote,local,mode,resume)
Parameter Description
ftp_connection Required. Specifies the FTP connection to be used (identifier of the FTP connection).
remote Required. The file name to be uploaded to the server.
local Required. Specifies the handle of the file opened.
mode

Required. Specifies the transfer mode. Possible values include:

  • FTP_ASCII
  • FTP_BINARY
resume Required. Specifies where to start copying in the local file. The default is 0.

Description

Parameter resume Only for PHP 4.3.0 and above versions

Example

This example copies text from "source.txt" to "target.txt":

<?php
$source = fopen("source.txt","r");
$conn = ftp_connect("ftp.testftp.com") or die("Could not connect");
ftp_login($conn,"admin","ert456");
echo ftp_fput($conn,"target.txt",$source,FTP_ASCII);;
ftp_close($conn);
?>

Output:

1