Like a lot of these Tips, this might only interest a few — but it might interest them a lot.
This will show you how to manipulate online files via a Windows icon.
For a quick example, let's say you run a blog or forum. You like the way the readers can post both pics and vids in the comments, but it worries you to allow it overnight. Some sworn enemy or evil troll might upload a bucketload of child porno at 3 AM and call the FBI. Sure, your good name will be cleared. Eventually.
So you set up a DOS batch file to perform a little online file magiculation. When you decide to call it quits for the day, you double-click on your 'Overnight' icon and it overwrites the config file for the comment editor with one that has the upload feature disabled. In the morning, when you're back in the saddle, you run the 'Normal' batch file and it overwrites the config file with the standard one.
You can also use it to automagically change themes (which changes the entire look of the site), sidebar pics, ad banners and videos, and you can include a timer in the DOS file so it'll change an item every X number of minutes or hours. You can then run that file when the computer starts up so you don't even have to think about it. All in all, a very slick little trick.
Overview
This is a little different than the standard batch file routine, so here's what's going to happen:
— The first batch file will do nothing more than run a second batch file, but this time in 'FTP mode'.
— The second batch file will be working online, which means it will use FTP commands, rather than standard DOS commands.
The full list of DOS FTP commands is here.
Here's the short list:
put — copies local file to remote
get — copies remote file to computer
delete — deletes remote file
rmdir — deletes remote directory
rename — renames remote file
cd — goes into directory, same as DOS
cd .. — backs out of directory, same as DOS
prompt — disables all the "yes/no?" prompting
quit — ends the file, closes the DOS window
The 'open' command goes to the site, with the next two lines expected to be the account login name & password.
Usage
To make a batch file, open Notepad and scribble down the commands. Save it someplace safe. Find the icon and rename the file extension from ".txt" to ".bat". If you're not seeing file extensions, go to Control Panel, Folder Options, the 'View' tab, uncheck 'Hide extensions...'.
Let's go ahead and use the above comment editor example, since it's one simple 'put' operation. We'll assume both primary batch files, both secondary batch files and the standard comment editor config file are in the same folder. We'll call the config file "config.php". Since we need two config files with the same name, we'll put the 'overnight' one (where the uploading feature has been disabled) in a sub-folder called 'night'.
Let's say you're closing down shop for the day and double-click on the 'Overnight' batch file. It says nothing more than:
ftp -s:overnight.txt
That runs "overnight.txt" in FTP mode.
It says:
prompt
open www.yourdomain.com
(account name)
(account password)
cd public_html
cd wp-content
cd plugins
cd cool_comment_editor
put night\config.php
quit
That goes to your site, goes into the folder where you want the config file copied, then copies the file from your computer to the site. It looks for the config file in the 'night' sub-folder.
Notes:
— The 'public_html' folder (called a 'directory' online) is the main public directory where all of the web files are kept. If it isn't 'public_html', it'll probably be 'htdocs'. This is a 'hidden' directory, so browsers don't have to include it, but nothing is hidden to DOS, so it's got to treat like any other directory.
— The next three directories above are for a WordPress site. Adjust to your own needs.
Come morning, you double-click on the 'Normal' batch file, which in turn runs 'normal.txt', which says:
prompt
open www.yourdomain.com
(account name)
(account password)
cd public_html
cd wp-content
cd plugins
cd cool_comment_editor
put config.php
quit
This one copies the config file in the same folder to the site, which reenables the upload feature.
General Notes:
— To upload multiple files, use the 'mput' command, like "mput *.php" to copy every file in the current folder with a '.php' file extension to the site.
— To use a timer, use the DOS 'timer' command in the primary batch file, like "timer /T 600" to pause the file 600 seconds, or 10 minutes.
— To start it up with Windows, d-r-a-g the primary batch file icon to the Start Menu, 'Programs', 'Startup' folder. Right-click on it and 'Rename' to get rid of the ".bat". Open its Properties and change the 'Run' to 'Minimized' so the ugly black DOS box doesn't pop up.
— For small files, like PHP files and pics, you might as well just use the 'put' command and copy them to the site afresh every time. This keeps the master files right there on your computer for easier monitoring and manipulation. For larger files, like videos, you'll want to use the FTP 'rename' command.
For example, let's say you have five videos you want to shuffle every hour throughout the day. Your primary batch file waits an hour, then executes the secondary batch file for video #2. It's currently playing video #1 which has been renamed "mainvideo.flv" for the online video player.
(go to site & folder)
rename mainvideo.flv video1.flv
rename video2.flv mainvideo.flv
quit
That renames video #1 back to its correct name and puts video #2 in the main slot. The primary batch file would then wait another hour, then execute the secondary file for video #3.
One nice thing about online DOS is that there's no "file in use" bullshit. The above script wouldn't work in a Windows environment because the video would be "in use" by the player and wouldn't be able to be renamed or copied over. So, once again, as with many other examples, this ancient, creaky, text-based operating system can do things even the highly-vaunted Windows can't do. We batch file freaks find that highly amusing.
Any questions or additions, like usual, give a holler.