SunshinePHP 2016

FTP context options

FTP context optionsFTP context option listing


Context options for ftp:// and ftps:// transports.


overwrite boolean

Allow overwriting of already existing files on remote server. Applies to write mode (uploading) only.

Defaults to FALSE.

resume_pos integer

File offset at which to begin transfer. Applies to read mode (downloading) only.

Defaults to 0 (Beginning of File).

proxy string

Proxy FTP request via http proxy server. Applies to file read operations only. Ex: tcp://


Version Description
5.1.0 Added proxy.
5.0.0 Added overwrite and resume_pos.


Note: Underlying socket stream context options
Additional context options may be supported by the underlying transport For ftp:// streams, refer to context options for the tcp:// transport. For ftps:// streams, refer to context options for the ssl:// transport.

add a note add a note

User Contributed Notes 1 note

php dot net at misterchucker dot com
6 years ago
This is an example of how to allow fopen() to overwrite a file on an FTP site. If the stream context is not modified, an error will occur: "...failed to open stream: Remote file already exists and overwrite context option not specified...".

// The path to the FTP file, including login arguments
$ftp_path = '';

// Allows overwriting of existing files on the remote FTP server
$stream_options = array('ftp' => array('overwrite' => true));

// Creates a stream context resource with the defined options
$stream_context = stream_context_create($stream_options);

// Opens the file for writing and truncates it to zero length
if ($fh = fopen($ftp_path, 'w', 0, $stream_context))
// Writes contents to the file
fputs($fh, 'example contents');
// Closes the file handle
'Could not open file.');
To Top