PHP FTP Error: 451 - Append/Restart not permitted

file, ftp, php

Solution

It means the FTP server on the other end doesn't support appending data to files. Since this is a server level configuration, unless you have administrative access to the server to change the setting, you really can't do anything about it.

The only thing I could suggest is to download the full file, append it locally, delete the remote and then upload the appended file. You could do this by using the PHP FTP library

$ftp = ftp_connect('yourserver.com');
$local = 'localfile.txt';
$remote = 'remote.txt';
if(ftp_login($ftp, 'username', 'password')){
    ftp_get($ftp, $local, $remote);
    $file = fopen($local, 'a');
    fwrite($file, 'your data here');
    fclose($file);
    ftp_delete($ftp, $remote);
    ftp_put($ftp, $remote, $local, FTP_ASCII); // It's a text file so it will be ASCII
    ftp_close($ftp);
}

Problem

When trying to `fopen` an existent file with `a` option, I'm receiving this error: Warning: fopen(ftp://...@sub.mysite.com/var/www/diversos/01_2014.txt) [function.fopen]: failed to open stream: FTP server reports 451 /var/www/diversos/01_2014.txt: Append/Restart not permitted, try again in /www/html/prod/my_transfer_file.php on line 150 my_transfer_file.php - Line 150 ``` fopen ('ftp://user:pass@sub.mysite.com/var/www/diversos/01_2014.txt', "a" ); ``` Is it a FTP or code issue? What do I do to solve this problem? Never saw this error before.

Original source