I'm toiling with the failed to open stream: HTTP wrapper does not support writeable connections issue ...

I'm attempting to write to a remote file, ie.,

$file = fopen ("http://64.175.23.250/rss/foo.txt", "w");

but get the failure message.

I'm running Apache on Mac OS X 10.3.9 and from what I can gather, it is configured to allow for the remote opening of a file - allow_url_fopen ON

My .ini file info is here:

http://64.175.23.250/test.php

I've got the permissions in the rss directory set to read & write, thus I'm baffled.

If anyone want to try writing to the file foo.txt on my server, please do so. I'm stuck ...

    it isnt possible to use fopen over http to write to a file, but you could use ftp to do it.

    the example on php.net's webpage is:
    fopen("ftp://user:password@example.com/somefile.txt", "w");

    you should have more luck trying it that way.

      Can you tell me which file I edit to enable ftp and/or declare a user/pw? Is it the config?

        you declare the username and password inside fopen. and it should already be enabled to use.

        fopen("ftp://user:password@example.com/somefile.txt", "w");

        see the user:password there, just change those to be your real ftp username and password details

          Drew, do I need to create a username/password within the Apache config file, or do I use the username/password associated with my eMac machine ? Thank you - Mark

            if you have an ftp server setup on that machine, you use the ftp username and password, if you dont, you will have to install an ftp server in order to use the ftp protocol.

              I'm using Mac OS X v10.3.9

              I have FTP Access checked in my network service panel (as well as the personal web sharing checked).

              I have username and password associated with this machine as the administrator, and also created a new user for ftp access in the event the admin pw/user are not sufficient.

              I followed these instructions to create a unique ftp user/pw
              http://www.ldml.com/services/support/macosx/ftpUserCreate.html

              That said ... I'm getting this error message (in the browser) when trying to open and write to a remote file using ftp

              Warning: fopen([url]ftp://...@easycalc.us/rss/foo.txt[/url]) [function.fopen]: failed to create stream: FTP server reports 229 Entering Extended Passive Mode (|||52236|)

                well, the ftp server appears to be working, as for that error, im not exactly sure what i means. check the ftp configuration and make sure passive mode is supported, or try turning it off since im not sure that error is complaining about not having passive, or having it.

                  May 12 14:52:02 adsl-64-175-23-250 xinetd[392]: service ftp, IPV6_ADDRFORM setsockopt() failed: Protocol not available (errno = 42)

                  May 12 14:52:02 adsl-64-175-23-250 xinetd[392]: START: ftp pid=3100 from=66.245.186.224

                    browser message:

                    Warning: fopen([url]ftp://...@easycalc.us/rss/foo.txt[/url]) [function.fopen]: failed to create stream: FTP server reports 553 /rss/foo.txt: Permission denied.

                      did you set the home dir of that ftp user to be the path to the webroot where /rss/foo.txt resides? it may be looking in /rss/foo rather than something like /home/user/www/rss

                        but I was able to confirm I can access

                        [url]ftp://64.175.23.250[/url]

                        and get to either the directory I created, or, the entire machine, depending on which user/pw I enter in the browser's ftp login panel

                          The odd part is if I use the system's admin name/pw, I should be able to access any file, anywhere - and I'm only trying to get into a text file with the web server.

                          I'm wondering if I need to configure the Apache server to recognize the request ... I say this because the file is in the root

                          http://www.easycalc.us/rss/foo.txt

                          and I'm using this php line of code

                          $file = fopen("ftp://name:password@easycalc.us/rss/foo.txt", "w");

                          (but using actual name and password in my code)

                          The file will display in a browser.

                          I do have ftp access to the machine using an ftp client and using name:password.

                          Just can't seem to get to it with the php code ...

                          Sorry for the smileys ... I can't seem to disable them .... if they show up, I intended to type a colon

                            im thinking if its gonna be very difficult to get the ftp working, you may be better off creating a script on the remote server, perhaps in the same folder as the .txt file which accepts post data, and when it receives it, the data is written to a file. for additional security you should hardcode a username/password into the script so not just any user can post data to the script and have it write to the file. this way you do...

                            <?php
                            //save.php
                            
                            $username = "drew010";
                            $password = "mypass";
                            
                            if($_POST['pass'] != $password && $_POST['user'] != $username) {
                              exit;
                            }
                            
                            $fp = fopen("./foo.txt", "w+");
                            fwrite($fp, $_POST['contents']);
                            fclose($fp);
                            
                            ?>
                            

                            now to get the file written to you can post data to that script with fsockopen...

                            <?php
                            
                            $user = "drew010";
                            $pass = "mypass";
                            $contents = "put/fetch whatever you want to go in foo.txt here";
                            
                            $poststr = urlencode("user=$user&pass=$pass&contents=$contents");
                            
                            $fp = @fsockopen("64.175.23.250", 80, $errno, $errstr, 10);
                            if (!$fp) die("Couldn't connect to remote host.  Reason: $errstr");
                            
                            fputs($fp, "POST /rss/save.php HTTP/1.0\r\n"
                            ."Host: 64.175.23.250\r\n"
                            ."Content-Type: application/x-www-form-urlencoded\r\n"
                            ."Connection: close\r\n"
                            ."Content-Length: " . strlen($poststr) .  "\r\n\r\n"
                            . $poststr . "\r\n");
                            
                            fclose($fp);
                            
                            ?>
                            

                              Hopefully this will work

                                I'm not sure why, but this line doesn't seem to be working ...

                                $fp=fopen("./foo.txt",_"w+");

                                I'm not getting anything written into that file .

                                What about creating a file (anywhere)? If that can be done from safe.php, I can then alter the path, and change the command to write to an existing file.

                                  after much trial and error, it appears the password and username is not coming through to save.php

                                  I put in this error check in the save.php script

                                  if($REQUEST['pass'] != $password)
                                  {
                                  $fp = fopen ("./foo.txt", "w+");
                                  fwrite ($fp, "got this pass from client:".$
                                  REQUEST['pass']);
                                  fclose ($fp);
                                  }

                                  and sure enough, the target file writes

                                  got this pass from client:

                                  is there something in the fopen() in the sending script that needs adjusting?

                                    ok get rid of the urlencode it was ruining the string, then it will work.

                                      if I put an '&' in the contents field

                                      $contents= "bread&butter is a great meal";

                                      the contents variable gets truncated at the '&'

                                      I use the '&' quite a bit, because I'm sending a set of form args as in

                                      $contents= "name=mark&title=owner&location=use"

                                      Is there a way to preserve those '&' symbols ?

                                        i suppose you can use htmlspecialchars to translate the contents variable's & into &amp; then some str_replace("&amp;", "&", $_POST['contents'] to turn it back on the receiving end.

                                          Write a Reply...