/**
 * Get the global FTP connection.
 *
 * This is used for local assets and public files by some sites.
 *
 * Returns the FTP resource or false on failure.
 *
 * @return FTPConnection | false
 */
function ftp(){
	static $ftp = null;

	if($ftp === null){

		if(!defined('FTP_USERNAME')){
			// Prevent the installer from freaking out.
			$ftp = false;
			return false;
		}

		if(!defined('FTP_PASSWORD')){
			// Prevent the installer from freaking out.
			$ftp = false;
			return false;
		}

		if(!defined('FTP_PATH')){
			// Prevent the installer from freaking out.
			$ftp = false;
			return false;
		}

		if(!FTP_USERNAME){
			// If there is no username for the FTP server, don't try to connect either.
			$ftp = false;
			return false;
		}

		$ftp = new FTPConnection();
		$ftp->host = '127.0.0.1';
		$ftp->username = FTP_USERNAME;
		$ftp->password = FTP_PASSWORD;
		$ftp->root = FTP_PATH;
		$ftp->url = ROOT_WDIR;

		try{
			$ftp->connect();
		}
		catch(\Exception $e){
			\Core\ErrorManagement\exception_handler($e);
			$ftp = false;
			return false;
		}
	}

	if($ftp && $ftp instanceof FTPConnection){
		try{
			$ftp->reset();
		}
		catch(\Exception $e){
			\Core\ErrorManagement\exception_handler($e);
			$ftp = false;
			return false;
		}
	}

	return $ftp;
}