Tuesday, December 14, 2010 at 7:24 PM.
myServerFarmRpcHandlers.saveApacheFile
on saveApacheFile (domain, path, s) {
<<Changes
<<12/14/10; 6:17:57 PM by DW
<<Rewrite to use FTP on the local server. It knows how to write to the filesystem without disturbing Apache.
<<11/29/10; 9:00:32 PM by DW
<<Logging code caused infinite recursion. Nuke it.
<<11/29/10; 3:43:26 PM by DW
<<Add logging code.
<<11/29/10; 2:31:24 PM by DW
<<Retrofit.
<<10/11/10; 5:00:26 PM by DW
<<Created.
local (adrdata = myServerFarmSuite.init (), startticks = clock.ticks (), lasterror);
if not adrdata^.prefs.apache.flRpcWriteEnabled {
scripterror ("Can't save the file because RPC writing is not enabled on the server.")};
local (pc = file.getpathchar (), folder = adrdata^.prefs.apache.folder + domain + pc);
myServerFarmSuite.rpcCheckClientId (client); //10/16/10 by DW
if adrdata^.prefs.ftp.enabled { //use FTP, 12/14/10 by DW
if path beginswith "/" {
path = string.delete (path, 1, 1)};
path = domain + "/" + path;
local (connection = tcp.ftp.openConnection (adrdata^.prefs.ftp.server, adrdata^.prefs.ftp.username, adrdata^.prefs.ftp.password));
tcp.ftp.writefile (connection, s, path);
tcp.ftp.closeConnection (connection);
return (true)}
else {
if not file.exists (folder) {
scripterror ("Can't save the file because there is no folder for the domain \"" + domain + "\".")};
local (f = folder + string.replaceall (path, "/", pc), i);
file.surefilepath (f);
for i = 1 to 10 {
try {
file.writewholefile (f, s);
<<log2.add (myServerFarmSuite.data.logSource, "Apache", "Wrote \"" + path + "\" on \"" + domain + ".\"", startticks)
return (true)}
else {
lasterror = tryerror};
clock.waitsixtieths (6)};
<<log2.add (myServerFarmSuite.data.logSource, "Apache", "Error writing \"" + path + "\" on \"" + domain + ":\"" + lasterror, startticks)
return (false)}}
<<bundle //test code
<<client = tcp.dns.getdottedid ("monster3.scripting.com")
<<saveApacheFile ("listings.opml.org", "subfolder/test.txt", clock.now ())
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.