Creating a file using FTP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Mr Tech
Forum Contributor
Posts: 424
Joined: Tue Aug 10, 2004 3:08 am

Creating a file using FTP

Post 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...
User avatar
omniuni
Forum Regular
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

Re: Creating a file using FTP

Post 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
User avatar
Mr Tech
Forum Contributor
Posts: 424
Joined: Tue Aug 10, 2004 3:08 am

Re: Creating a file using FTP

Post 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.
Post Reply