User:MarkTraceur/OPW/Tugce application task

From mediawiki.org
$host="ftp.websitename.com ";
$user="user";
$password="password";
$remotefile="";
$localfile="";



//for connecting ftp


$connect=ftp_connect($host);


if(!$connect){

	echo " couldnt connect ftp server";
	exit;
	}echo "connect successful $host ";

	
	// ftp login
	
@$result=ftp_login($connect,$user,$password);

if(!$result){

	echo " username/password combination wrong, cant connect ftp";
	
	ftp_quit($connect);
	exit;
	
echo "connection successful";

//checking dates for update

		echo " reading dates";
		
if(file_exits($localfile)){
		$localtime=filetime($localfile);
		echo "update date " ;
		echo "Date("G:i-m-y", $localtime) ;
		
		}
		
else{
	$localtime=0;
	$localtime=ftp_mdtm($connect,$remotefile);
	if(!(remotetime>=0)){
		
		echo "cant change file's date " ;
		$remotetime=$localtime+1;
		
		}
	else{
		echo "dates updated";
	} }
if(!($remotetime>$localtime)){
	echo "computer's date isnt correct";
	exit;
	}

	
	//for downloading files 
	
echo "downloading files ";

$fp=fopen($localfile,"w");
if(!($success=ftp_fget($connect,$fp,$remotefile,FTP_BINARY)){
	//if we're here, we couldnt download file
	echo " download unseccessful";
	ftp_quit($connect);
	exit;
	}
fclose($fp);
	echo "download successful ";
	
	// quit connection
	ftp_quit($connect);