Req #74582 [Opn->Csd]: Can not append to remote files with the ftp_* API

From: Date: Tue, 19 Jun 2018 20:29:39 +0000
Subject: Req #74582 [Opn->Csd]: Can not append to remote files with the ftp_* API
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-215800@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=74582&edit=1 ID: 74582 Updated by: nikic@php.net Reported by: ndobromirov at gmail dot com Summary: Can not append to remote files with the ftp_* API -Status: Open +Status: Closed Type: Feature/Change Request Package: FTP related Operating System: All PHP Version: 7.1.5 -Assigned To: +Assigned To: nikic Block user comment: N Private report: N New Comment: ftp_append() has been added in PHP 7.2. Previous Comments: ------------------------------------------------------------------------ [2017-07-09 01:14:15] gmblar+php at gmail dot com You cannot use $startpos in ftp_put to append data to an existing file, because the $startpos seek the position in the local and the remote file. ------------------------------------------------------------------------ [2017-05-12 12:50:49] ndobromirov at gmail dot com Description: ------------ --- From manual page: http://www.php.net/ref.ftp --- This was tested against 5.6, but the ftp_append method is not present in PHP 7 too. Developers can append to FTP files through the streaming interfaces, but this is creating new FTP connections every time: file_put_contents('ftp://user:pass@exmaple.com:21/test.txt', "test\n", FILE_APPEND); The same is not possible through the dedicated FTP API provided with all of the ftp_* functions. There is no ftp_append function. And aparently this is also not possible with ftp_put and using the last parameter - offset (see test script). Test script: --------------- // Init... $ftp_connection = 'ftp://user:pass@example.com:21'; list ($source, $download) = ['test.txt', 'download.txt']; file_put_contents($source, "test\n"); // Connecnt... $remote = '/test_remote.txt'; $dsn = parse_url('ftp://user:pass@ftp:21'); if (!(($ftp = ftp_connect($dsn['host'], $dsn['port'])) !== false && ftp_login($ftp, $dsn['user'], $dsn['pass']))) { die('No log-in'); } // Test... @ftp_delete($ftp, $remote); for ($i = 0; $i < 3; ++$i) { if (ftp_put($ftp, $remote, $source, FTP_BINARY, $i ? ftp_size($ftp, $remote) : 0)) { ftp_get($ftp, $download, $remote, FTP_BINARY); echo file_get_contents($download), "\n"; } } Expected result: ---------------- test test test test test test Actual result: -------------- test test test ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=74582&edit=1

« previous php.bugs (#215800) next »