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

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条)

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分