Skip to content

Commit bdb01a6

Browse files
committed
bug #11772 [Filesystem] Add FTP stream wrapper context option to enable overwrite (Damian Sromek)
This PR was submitted for the master branch but it was merged into the 2.3 branch instead (closes #11772). Discussion ---------- [Filesystem] Add FTP stream wrapper context option to enable overwrite | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | License | MIT Without this change it's not possible to override a file on FTP by calling Filesystem::copy($originFile, $targetFile, true) as PHP/FTP server responds with error like: fopen(ftp://...@ftp/file.txt): failed to open stream: Remote file already exists and overwrite context option not specified FTP server reports 213 166440 [] TODO: Write an integration tests? How? Use some real FTP server? Commits ------- c056a9c [Filesystem] Add FTP stream wrapper context option to enable overwrite (override)
2 parents 2c9496b + c056a9c commit bdb01a6

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/Symfony/Component/Filesystem/Filesystem.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ public function copy($originFile, $targetFile, $override = false)
5050
if ($doCopy) {
5151
// https://bugs.php.net/bug.php?id=64634
5252
$source = fopen($originFile, 'r');
53-
$target = fopen($targetFile, 'w');
53+
// Stream context created to allow files overwrite when using FTP stream wrapper - disabled by default
54+
$target = fopen($targetFile, 'w', null, stream_context_create(array('ftp' => array('overwrite' => true))));
5455
stream_copy_to_stream($source, $target);
5556
fclose($source);
5657
fclose($target);

0 commit comments

Comments
 (0)