Page 1 of 1

Creating a file using FTP

Posted: Wed Aug 13, 2008 11:06 pm
by Mr Tech
I'm trying to create a page using ftp...

Code: Select all

$content = "Enter your html here...";
 
$ftpstream = @ftp_connect($ftp_server);
$login = @ftp_login($ftpstream, $ftp_user_name, $ftp_user_pass);
if($login) {
    //$temp = tmpfile();
    $temp = fopen('php://temp', 'r+');
    fwrite($temp, $content);
    rewind($temp);      
    @ftp_fput($ftpstream, $dirpath, $temp, FTP_BINARY);
} else {
    echo 'Can\t connect to ftp';
}
ftp_close($ftpstream);
It isn't throwing any errors but it isn't creating the file... originally I was using the tmpfile() function to create the temporary file but I tried another method which doesn't work either...

Re: Creating a file using FTP

Posted: Wed Aug 13, 2008 11:34 pm
by omniuni
If your file contains HTML/text why are you writing it in binary mode? Perhaps try ASCII instead and see what that does?

If you don't mind my asking... why exactly are you trying to create the file via FTP?

-OmniUni

Re: Creating a file using FTP

Posted: Thu Aug 14, 2008 12:34 am
by Mr Tech
I already tried ASCII... It didn't work either...

I'm creating a file because it's part of an old CMS I created years ago for a client. It used to write files to writeable folders but now I can no longer have the folders writeable due to security issues.