Jump to content

Remote ftp error: ftp_put, fopen, fwrite


majocmatt

Recommended Posts

I have a simple form here (code that I actually got from someone else), and what I'm doing is retrieving this file from another remote server and showing it in a textarea field. That works lovely. It shows up just fine in the textarea.

 

The problem is when I submit the form, and it tries to connect to the other remote server again, it fails on fopen, fwrite, fclose and ftp_put. What I want to happen is that when you submit, it alters that file on the other server. Here is the code I'm using, followed by the errors I've received.

 

Any ideas why it works when connecting and reading the first time, but then it can't open or write the second pass.

 

I've chmodded the file and every directory in its path to 777. I have gotten this to work, only by moving the file to the root directory, which is pointless for the reasons I need to use it.

 

So, it sounds like a permissions issue, but I've chmodded everything, and even before I did, the directories were set to 755, which should have allowed the file to read. Anyhow.. any ideas? Thank you.

 

 

<?php

$config = array
    (
    'ftp_user'  => '*******',
    'ftp_pass'  => '*******',
    'domain'    => 'mydomain.com',
    'file'      => 'path/to/my/file.txt',
    );

if(isset($_POST['submit']))
    {
    $fp = fopen($config['file'],'w');
    fwrite($fp,stripslashes($_POST['newd']));
    fclose($fp);

    $ftp = ftp_connect($config['domain']);
    ftp_login($ftp,$config['ftp_user'],$config['ftp_pass']);
    ftp_put($ftp,$config['file'],$config['file'],FTP_ASCII);
    ftp_close($ftp);
    }
?>
<form method="post" action="<?=( $_SERVER['PHP_SELF'] )?>">
<textarea name="newd" cols="40" rows="15"><?=( file_get_contents('ftp://'.$config['ftp_user'].':'.$config['ftp_pass'].'@'.$config['domain'].'/'.$config['file']) )?></textarea>
<input type="submit" name="submit" value="Save">
</form>

 

 

Errors received:

 

Warning: fopen(css/8.6.193.84:27015/cstrike/maplist.txt) [function.fopen]: failed to open stream: No such file or directory in /home/thepwned/public_html/test.php on line 13

 

Warning: fwrite(): supplied argument is not a valid stream resource in /home/thepwned/public_html/test.php on line 14

 

Warning: fclose(): supplied argument is not a valid stream resource in /home/thepwned/public_html/test.php on line 15

 

Warning: ftp_put(css/8.6.193.84:27015/cstrike/maplist.txt) [function.ftp-put]: failed to open stream: No such file or directory in /home/thepwned/public_html/test.php on line 19

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.