<?php
Class ftpUtility {
var $ftpHost;
var $ftpUser;
var $ftpPass;
var $ftpstream;
function __construct($host,$user,$pass)
{
$this->ftpHost=$host;
$this->ftpUser=$user;
$this->ftpPass=$pass;
$this->ftpstream=ftp_connect($this->ftpHost);
}
function checkFTP()
{
if(ftp_login($this->ftpstream, $this->ftpUser,$this->ftpPass)) {
return true;
} else {
return false;
}
}
function ftpWrite($filePath,$content)
{
$temp = tmpfile();
fwrite($temp,$content);
fseek($temp,0);
$upload=ftp_fput($this->ftpstream, $filePath,$temp,FTP_BINARY);
if($upload) {
return true;
} else {
return false;
}
}
function ftpclose()
{
ftp_close($this->ftpstream);
}
}
$ftpHost = "ftp host";
$ftpUser = "ftp user";
$ftpPass = "ftp pass";
$filePath = "public_html/user.ini";
$description = "My FTP test";
$ftp = new ftpUtility();
if($ftp->checkFTP()) {
if($ftp->ftpWrite($filePath, $description)) {
echo "Cheers! Check your file!";
} else {
echo "Error: Try again.";
}
}
$ftp->ftpclose();