$host = "ftp.example.com";
$user = "anonymous";
$pass = "";
// You get this from the form, so you don't need to do move_uploaded_file()
$fname = "/public_html/new_file.txt";
$fcont = "content";
function ftp_writeFile($ftp, $new_file, $content, $debug=false) {
extract((array)pathinfo($new_file));
if (!@ftp_chdir($ftp, $dirname)) {
return false;
}
$temp = tmpfile();
fwrite($temp, $fcont);
rewind($temp);
$res = @ftp_fput($ftp, $basename, $temp, FTP_BINARY);
if ($debug) echo "a- '$new_file'".(($res)?'':" [error]")."<br/>";
fclose($temp);
return $res;
}
$ftp = ftp_connect($host);
if (!$ftp) echo "Could not connect to '$host'<br/>";
if ($ftp && @ftp_login($ftp, $username, $password)) {
ftp_writeFile($ftp, $fname, $fcont, true);
} else {
echo "Unable to login as '$username:".str_repeat('*', strlen($password))."'<br/>";
}
ftp_close($ftp);
http://au.php.net/manual/en/book.ftp.php
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…