In PHP, ftp_fput() uploads data from an open local file handle to a file on the FTP server. It is the stream version of ftp_put().
You open a file or memory stream yourself and pass the handle, so you can upload text built in memory without creating a temporary file on disk. The upload starts from the current position of the handle.
Syntax
Call ftp_fput() with the values you need. Start with this line.
Starts writing to the remote file at byte 1024 (resume).
The handle must be opened for reading and be at the position where you want to start, so use rewind() if you wrote data to it first. From PHP 8.1 the first argument is an FTP\Connection object.
Library declarations
PHP
ftp_fput(FTP\Connection $ftp, string $remote_filename, resource $stream, int $mode = FTP_BINARY, int $offset = 0): bool
Parameters
Parameter
Description
ftp
Required. The FTP\Connection object returned by ftp_connect() or ftp_ssl_connect().
remote_filename
Required. The path of the file on the server where the data will be stored.
stream
Required. An open file pointer to read the data from.
mode
Optional. The transfer mode, FTP_ASCII or FTP_BINARY. The default is FTP_BINARY.
offset
Optional. The position in the remote file to start uploading to. The default is 0.
Return Value
Return Value
Description
bool
true on success, false on failure.
PHP Examples
Example 1 — Upload From a File Handle
Open a local file for reading and send it to the server. The host and login are placeholders.