Page 1 of 1

FTP files?

Posted: Mon Sep 15, 2003 6:34 pm
by Mr. Tech
Well I found out that you can't smod files that aren't created by PHP. So I tried an ftp script. This is it:

Code: Select all

<?php
$conn_id = @ftp_connect('$ftp_server');
$login_result = @ftp_login($conn_id, "$ftp_user", "$ftp_pass");

if ((!$conn_id) || (!$login_result)) { 
        echo "<p>FTP connection has failed!";
        echo "<p>Attempted to connect to $ftp_server for user $ftp_user"; 
        exit; 
    } else {
        echo "<p>Connected to $ftp_server, for user $ftp_user";
    }


$text = "hi!";

$tmpfname = @tempnam('/tmp', 'cfg');
$fp = @fopen($tmpfname, 'w');
fwrite($fp, $text);
fclose($fp);

$upload = ftp_put($conn_id, 'file.html', $tmpfname, FTP_BINARY);
unlink($tmpfname);

if (!$upload) { 
        echo "<p>FTP upload has failed!";
    } else {
        echo "<p>Uploaded $tmpfname to $ftp_server as file.hml";
    }
ftp_close($conn_id);
?>
Now it says it connects ok and writes ok but it actually doesn't write in the file. Any ideas why?