Oct. 20, 2012

Needed a script to search through all the pages on this site over ftp and perform a find/replace on the HTML source. It would probably be better to have coded each page in such a way that elements common to multiple pages are referenced from a single location (sort of like CSS), but I didn't write the pages that way. Maybe this script will be useful if I ever decide to insert such code into every page. Script is written in Python, makes use of the ftplib library.

FTP Find/Replace Script (Python)

Update Dec. 12, 2012: Fixed the full directory-path issue for the blacklist. Also fixed the escape sequence issue (only for '\n' and '\t' for now - it's very easy to add other sequences if needed). When entering text to find or replace, use two backslashes for escape sequences (ex. '\\n'. Also, the script should be run with sudo, otherwise the ftp module has problems connecting.

Update Dec. 8, 2012: Found out that the blacklist doesn't support directory root paths (e.g. to blacklist the '/sw/findreplace' directory, you would have to just blacklist 'findreplace' and hope that no other directories share that name. Shouldn't be too hard to fix - I'll post an update when/if I fix this. Also, the script can't deal with newlines ('\n'), tabs ('\t') or similar escape sequences - this is also something I'd like to fix, but don't know how off the top of my head. I updated the navigation menu on the left using this script - you'll notice in the source that the new Contact link isn't on it's own line - that's because of this bug.