php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40574 file_put_contents fails with ftp wrapper
Submitted: 2007-02-21 10:03 UTC Modified: 2007-03-14 01:00 UTC
Votes:10
Avg. Score:4.6 ± 0.7
Reproduced:9 of 10 (90.0%)
Same Version:5 (55.6%)
Same OS:2 (22.2%)
From: arnaud@php.net Assigned:
Status: No Feedback Package: Streams related
PHP Version: 5.2.1 OS:
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: arnaud@php.net
New email:
PHP Version: OS:

 

 [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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-02-21 10:06 UTC] arnaud@php.net
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)
 [2007-02-21 13:32 UTC] tony2001@php.net
<?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?
 [2007-03-01 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2007-03-05 13:48 UTC] arnaud@php.net
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 1
 [2007-03-06 11:55 UTC] tony2001@php.net
Can't reproduce using vsftpd.
 [2007-03-14 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2007-03-28 14:34 UTC] mat at actiondb dot com
The 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
 [2007-05-30 00:49 UTC] lc at nospam dot com
I am also getting the same behavior mat describes using 5.2.2  The only 
way to get a successfull upload using file_put_contents using a ftp 
stream is when the file being uploaded does not exist on the server.  
Subsequent uploads with the stream_context of overwrite being true 
result in a zero-byte file
 [2012-01-10 15:17 UTC] simonsimcity at gmail dot com
I think I have the same issue reproduced in a slightly different way:

In one script I tried to upload a file using WebDAV. Therefore I used the PHP-Library HTTP_WebDAV_Client_Stream.
This library registers the streams webdav:// and webdavs://

When I try to save into that stream using file_put_contents() it fails returning "Only 0 of 160 bytes written, possibly out of free disk space" .. but the work-arround (using fopen, fwrite and fclose) works.

Here's the code:
http://pastebin.com/8tDqyg4K
 [2012-01-10 15:25 UTC] simonsimcity at gmail dot com
Please ignore/delete my last comment. I was not seriously checking the script I run.
The PEAR-library seem to have an error here because I do not get an error on using fopen, frwite and fclose, but the file is not written.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 02:01:28 2024 UTC