php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #74582 Can not append to remote files with the ftp_* API
Submitted: 2017-05-12 12:50 UTC Modified: -
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: ndobromirov at gmail dot com Assigned:
Status: Open Package: FTP related
PHP Version: 7.1.5 OS: All
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: ndobromirov at gmail dot com
New email:
PHP Version: OS:

 

 [2017-05-12 12:50 UTC] 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


Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-07-09 01:14 UTC] 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.
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sat Nov 18 15:03:12 2017 UTC