Monday, November 08, 2010 at 12:03 AM.

system.verbs.builtins.html.fileWriters.ftp.startup

on startup (adrObject, adrStorage) {
	<<The startup script is called when a rendering session is starting up.
		<<A rendering session is usually one of two things:
			<<1) A single page is being rendered.
				<<In this case this script is called before that page has been rendered.
			<<2) An entire table is being rendered.
				<<In this case this script is called after before any of the pages in the table have been rendered.
			<<Other types of rendering sessions may exist in the future,
				<<but the pattern will remain the same.
		<<adrObject is the address of the object being rendered.
			<<It might be a page or it might be a table.
		<<adrStorage is the address of private storage for this file writer for this session.
	<<This particular script opens the ftp connection at startup
		<<5/1/03; 10:35:13 PM by EDS
	try {
		if not defined (adrStorage^.adrConnectionTable) {
			local (username, password);
			local (host);
			local {
				adrFtpSite = adrStorage^.adrFtpSite};
			username = adrFtpSite^.account;
			password = adrFtpSite^.password;
			host = adrFtpSite^.domain;
			local (adrConnectionTable);
			adrConnectionTable = tcp.ftp.openConnection(host, username, password, flMessages:false);
			adrStorage^.adrConnectionTable = adrConnectionTable;
			if not defined(adrStorage^.adrConnectionTable^) {
				scriptError("Unknown connection error")};
			bundle { // set site root directory
				siteRootDirectory = adrFtpSite^.directory;
				if not (siteRootDirectory beginsWith "/") {
					<</ means at the root
						<<no / means relative to login directory. 
						<<hardcoding path to login directory is stupid. 
						<<but broke abstraction barrier here getting the directory straight from the conn table. 
					siteRootDirectory = string.popTrailing(adrStorage^.adrConnectionTable^.rootDirectory,'/')+"/" + siteRootDirectory};
				if not (siteRootDirectory endsWith "/") {
					siteRootDirectory = siteRootDirectory + "/"};
				if siteRootDirectory == "//" {
					siteRootDirectory = "/"};
				adrStorage^.siteRootDirectory = siteRootDirectory}}}
	else {
		scriptError("Error in filewriters.ftp.startup setting up ftp connection: "+tryError)};
	adrStorage^.adrObject = adrObject;
	return (true)}



This listing is for code that runs in the OPML Editor environment. I created these listings because I wanted the search engines to index it, so that when I want to look up something in my codebase I don't have to use the much slower search functionality in my object database. Dave Winer.