Semi-Automatic Uploading with Windows Batch Files

This project will allow the user to upload—with a single click—specific files to a Web server.

Requirements:
An account on a file server allowing FTP connections

Sections of this project:

  1. Creating a Script for the Command-Line FTP Client
  2. Passing the Script to the FTP Client
  3. Creating the Batch File to Run the FTP Client
  4. Relative File Locations
  5. Adding the Batch File to the Quick Launch Bar
  6. Customizing the Tool
  7. Security Issues

Introduction

If you have ever found yourself making frequent changes to a Web page, or set of pages, you know how inefficient the process can be. No matter how streamlined your FTP software is, you'd probably prefer to click a single icon and have your pages updated on the server.

In this project, we will work with the command-line FTP client in Windows, and a batch file, to automate the upload process. In order to get the operation down to a single click, we will use the Quick Launch portion of the Windows Taskbar. Finally, we will customize the appearance of the running batch file.

If you have never used the Windows FTP client, you can follow a short tutorial here.

Creating a Script for the Command-Line FTP Client

The first step is to write out a list of commands to be executed by the FTP client. The list should be created in Notepad, with each command on its own line. Save the file and you have an FTP script.

An FTP script should look something like this:

In this example, the username for the remote server account is kluge and the password for the account is pr0ject71. These two pieces of information must appear in this order as the first items of the script.

The third line indicates that the following data transfer should take place in ASCII mode.

Line four changes to the directory called public_html on the remote server, while line five uploads the desired file. Notice that the version of index.html being uploaded is located in the same directory as the script file, so it does not require a full file path (e.g. "C:\Documents and Settings\kluge\index.html"). File locations will be discussed later in the tutorial.

The last two lines clearly close the connection to the remote server and then quit the FTP client.

You may have noticed that the title of the script file does not have the standard .txt extension. No extension is required for a script. I don't like making files that contain my password information any easier to find and read than necessary.

Passing the Script to the FTP Client

For this project, two arguments will be passed when invoking the program. The first is the path to the script file, and the second is the name of the remote server.

The syntax, if entered at the Command Prompt, would look like this:

> ftp -s:smp01 klugeserver.com

Where -s: is a flag indicating that a script file is being named, smp01 is the name of the script file and klugeserver.com is the name of the remote server (an IP address will also work).

Notice that in this example, the file smp01 is located in the same directory that is the present working directory of the FTP client. Otherwise, you will need to enter a full file path from C: (e.g. -s:"C:\Documents and Settings\kluge\smp01", where the double quotes are necessary because of the spaces in the Documents and Settings directory name).

Creating a Batch File to Run the FTP Client

Now we have a single command that uploads our file to a server. Next we want to do away with the need for any keystrokes. It's time for a Batch file.

A Windows batch file (.bat) is a script, similar to the one we’ve just created. In this case, the script is made up of one or more commands that will be executed by the Command Prompt. When the batch file is saved, double-clicking its icon will cause the contents of the file to be passed to the command-line interpreter.

For our project, the batch file contains the single command that we’ve just used to invoke the FTP client.

Here is our batch file, created in Notepad:

Relative File Locations

It’s a good idea to stop here and consider the relative locations of the files involved in this project. First we have the index.html file that is being uploaded. Once its path is added to the FTP script, it must remain in its place or the FTP client will not find it.

(You might consider creating a shortcut to the index.html file. The shortcut can be placed on the start menu, desktop, or any other easily accessed spot.)

The FTP script must not be moved once its path is given in the batch file. Notice that in our current project, the script and batch files live in the same directory. If not, the batch file would need a full path to find the FTP script.

Finally we have the batch file. If the FTP script location is listed as a full path, you can move the batch file anywhere, at any time, and it will work properly. The remainder of this tutorial will assume that all three files are located in the C:\Documents and Settings\kluge\ directory.

Adding the Batch File to the Quick Launch Bar

We've reduced the process of uploading a file to double-clicking on the batch file icon. We could stop here and have a useful tool, but with a little polish this process can be streamlined and customized even farther.

Any application that is added to the Quick Launch bar (usually the part of the taskbar to the right of the Start button), can be started with a single click. Our batch file is an excellent candidate.

If you do not have the Quick Launch bar activated, right-click the taskbar and select Properties on the context menu that appears. In the Taskbar Appearance section, check Show Quick Launch and click Apply. The Quick Launch bar will now appear to the right of the Start button.

To add the batch file, first create a shortcut by right-clicking on the icon and selecting Create Shortcut. Now you can drag the shortcut to the Quick Launch bar and drop it in place.

The process is now as streamlined as possible, requiring a single click to upload any files listed in the FTP script.

Customizing the Tool

There are two aspects of this tool that you might want to customize. The first is the icon for the batch file that is now displayed on the Quick Launch bar. You can change this icon by right-clicking it and selecting Properties from the context menu.

At the bottom of the Shortcut section you’ll see a button clearly labeled Change Icon. When you click here, you’ll be presented with a browse window. You can either select an icon from the default .dll file that opens (C:\windows\system32\shell32.dll) or hunt around for icons on your system.

[Note: If you want to remove the arrow overlay from your shortcuts icons, download TweakUI from Microsoft. It will give you the option of customizing this overlay or removing it entirely.]

The second customization to consider is the display of the Command Prompt window that will appear when you click this shortcut.

Again, right-click the shortcut icon and select Properties from the context menu. Switch to the General tab. At the top left you will see your new icon with a text field to the right. This text field will be displayed when you mouse over the icon on the Quick Launch bar, and will also be the text displayed in the title bar of the Command Prompt window when the batch file runs.

Change this text to whatever you wish and move on to the other tabs on the Properties form. At this point you can chose to customize the Command Prompt window however you’d like. You can even choose to have it run minimized (Shortcut tab: Run field). You can customize the background and text color (Color tab), the font size (Font tab), the window size and the location on your desktop where the window appears (Layout tab).

Security Issues

Because the FTP script lists your remote server username and unencrypted password, there is a security issue to keep in mind. If you physically share your computer with anyone, they could potentially find this file and have your login information. But in order to use it, they would need to know what remote server this information was for. This means that they would need to locate the batch file as well (as the batch file lists the remote server by name). This is why you should save the FTP script file with an arbitrary name and no file extension. You might even keep this script in a system folder where it will be lost in a sea of similarly arbitrary file names.

It is more important to place the batch file someplace where it could easily be overlooked, as it must retain the .bat file extension to function properly. But keep in mind that the shortcut on the Quick Launch bar points to the location of the actual batch file. So, as you can see, your best bet is to make sure that your computer is not accessible by anyone you don’t trust.