douan6815 2014-01-29 14:09
浏览 330
已采纳

PHP FTP错误:451 - 不允许附加/重新启动

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.

  • 写回答

2条回答 默认 最新

  • dousi1097 2014-02-04 01:57
    关注

    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);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?