|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-02-21 10:03 UTC] arnaud@php.net
Description:
------------
The ftp wrapper fails on writing operations. I tried file_put_contents() with a stream context and overwrite set to true. I tried using fopen() but it fails.
A file_get_contents() works properly though.
When looking at the network traffic I see the following:
port > ftp [SYN] ...
ftp > port [SYN, ACK] ...
port > ftp [RST] ...
I actually use 5.2.0 but this should not make any difference.
Reproduce code:
---------------
var_dump(file_put_contents('ftp://user:pass@host/test.txt', 'fooo'));
PHP Warning: file_put_contents(): Only 0 of 4 bytes written, possibly out of free disk space in php shell code on line 1
Warning: file_put_contents(): Only 0 of 4 bytes written, possibly out of free disk space in php shell code on line 1
bool(false)
Expected result:
----------------
file created with the string as content.
Actual result:
--------------
Fails.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 07 20:00:01 2025 UTC |
I've ran an strace, here is the result strace -e network php ftp.php socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 3 connect(3, {sa_family=AF_INET, sin_port=htons(21), sin_addr=inet_addr("192.168.20.13")}, 16) = -1 EINPROGRESS (Operation now in progress) I'd like to add that using the ftp extension works properly (ftp_connect(), ftp_login(), ftp_put() sequence)<?php $c = stream_context_create(array("ftp" => array("overwrite"=>true))); var_dump(file_put_contents("ftp://localhost/upload/data.txt", "data", 0, $c)); ?> outputs: int(4) Check your FTP server?Using proftpd with authentication fails php > $c = stream_context_create(array("ftp" => array("overwrite"=>true))); php > var_dump(file_put_contents("ftp://xx:xx@localhost/data.txt", "data", 0, $c)); Warning: file_put_contents(): Only 0 of 4 bytes written, possibly out of free disk space in php shell code on line 1The example: <?php $c = stream_context_create(array("ftp" => array("overwrite"=>true))); var_dump(file_put_contents("ftp://localhost/upload/data.txt", "data", 0, $c)); ?> Will output int(4), but if you check the FTP server, the file will probably be 0 bytes. I have been trying to resolve this problem myself, and it seems that if the file is greater than around 30K-35K (maybe it's 32K?), the upload works. I'm using PHP 5.2.1 on Apache 2.2.4 installed on Win2k3