We are a commune of inquiring, skeptical, politically centrist, capitalist, anglophile, traditionalist New England Yankee humans, humanoids, and animals with many interests beyond and above politics. Each of us has had a high-school education (or GED), but all had ADD so didn't pay attention very well, especially the dogs. Each one of us does "try my best to be just like I am," and none of us enjoys working for others, including for Maggie, from whom we receive neither a nickel nor a dime. Freedom from nags, cranks, government, do-gooders, control-freaks and idiots is all that we ask for.
Our Recent Essays Behind the Front Page
Wednesday, December 19. 2012
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.
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
The 'open' command goes to the site, with the next two lines expected to be the account login name & password.
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:
That runs "overnight.txt" in FTP mode.
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.
— 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:
This one copies the config file in the same folder to the site, which reenables the upload feature.
— 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)
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.
Display comments as (Linear | Threaded)
Shit, this tip is slicker than snot on a glass doorknob. I've whupped up lots of batch files in my day, but never had a clue it worked online. Gotta go play!
"cd online" is definitely a new experience.
Good luck. :)
I assume that your ftp client uses a secure cnxn. If not you're sending your id/pw in the clear.
There's no client involved. It's just a one-time direct connect, like Telnet. I discussed the security of it ages ago with a BlueHost guy and he said all major web hosts use secure connections for such as this, in the sense that they don't allow 'anonymous' FTP connections on any of their sites.
Doc, I agree with Tom. Anonymous FTP only means that there is no authentication to the FTP server (no username or password). However, FTP transmits all information "in the clear" with no encryption, including the username and password. So if you used your script at a location with open wi-fi or an unprotected wired network, anyone will be able to gather the FTP username and password. Telnet is just as unsecure as FTP.
Safer procedure would be using Secure Shell (SSH) or Secure Copy (SCP) to do the file transfers. The entire connection is encrypted, and requres authentication (username and password). You can even use public/private key pairs for more security.
We're talking about a normal computer using a normal ISP and web host. People using unsecure wi-fi would be smart enough not to do anything too dicey on it. People not smart enough to know that wouldn't be smart enough to do the stuff in this article.