The Windows Command-Line FTP Client

This tutorial walks the user through the basics of the command-line FTP client built into most Windows operating systems.

Sections of this project:

  1. Invoking and Quitting the FTP Client
  2. Connecting to a Server
  3. Changing Directories
  4. Changing the Transfer Mode
  5. Putting Files
  6. Getting Files
  7. Closing and Quitting
  8. Command-Line Arguments

Introduction

Most of us who use FTP to transfer files have a favorite graphical client, like WS_FTP, CuteFTP or the client built into Dreamweaver. With powerful software like this available, it’s easy to forget that Windows has its own—albeit text-based—client.

But if you have never used the command-line FTP client on Windows, you should take a moment to follow this tutorial and familiarize yourself with it. You never know when you’ll find yourself on a strange computer, needing to upload a file.

Invoking and Quitting the FTP Client

There are two primary ways to start the FTP client: from the Command Prompt and from the Start Menu’s Run feature.

Using:
The Command Prompt can be reached from the Start --> Programs menu. The prompt will show your present working directory, which should look something like:

C:\Documents and Settings\username>

Enter ftp at this prompt. You will see the prompt change from your present working directory to:

ftp>

You are now ready to connect to a remote server and transfer files.

While you have FTP running, enter help to bring up a list of available commands that can be used. To learn more about a command, type help command.

To end the FTP session, type quit.

Using:
To use the Run feature to access FTP, first locate it on the Start Menu and click once.

When the Run window appears, enter ftp and click OK. A Command Prompt window will appear with FTP already running.

Connecting to a Server

At the ftp> prompt, type open hostname where hostname is the domain name or numerical IP address of the remote server (e.g. open troybrophy.com).

If you have entered a valid hostname you should eventually see the greeting, Connected to hostname. When the FTP server is ready it will notify you, and then ask for the account’s username, followed by the password.

Bear in mind that although you can see what you have typed for a username, the window will not echo back password keystrokes, so you will not see your password as you type it.

(In the example above, you see User (troybrophy.com:(none)): troy. The :(none) refers to the fact that no specific port number was entered at the time of connect. Most FTP servers use ports 20 or 21, but if your remote server is configured differently you can specify a connection port with open hostname:port.)

Changing Directories

Now that you are connected to your remote server, you will want to transfer files to specific directories. Bear in mind that the FTP server will start you in the home directory for your account. This may not be the directory where you want to place your files.

Use the pwd (present working directory) command to determine which directory you are in on the remote host.

Use the ls command to list all files and subdirectories in the present working directory.

To change to a new directory, use the cd command (or the lcd command to affect your local machine), followed by the name of the directory to change to:

cd public_html
Changes to a subdirectory called public_html

cd ..
Changes to the parent directory (goes 'back out' of a directory to the one above it)

cd public_html/images/backgrounds
Changes to the directory called backgrounds, which is a subdirectory of images, a subdirectory of public_html

lcd "c:\Program Files"
Changes the working directory on the local machine to Program Files

Changing the Transfer Mode

Once you have located the target directory on the remote server, you can begin the process of uploading (or downloading) files. At this point it is a good idea to set the file transfer mode. This tells the FTP client whether to send the file as ASCII text or as a binary.

If you are uploading images, multimedia, database data or executable files, you will want to toggle the transfer mode to Binary. This is done simply by issuing the command: binary

Likewise, for all text-based and script files (HTML, PHP, CSS style sheets, etc.) you should issue the command: ascii

ASCII is the default setting, but you can always check which mode is set by using the status command.

Putting Files

The command used to upload a file to a remote directory is put:

put index.html
Uploads the file index.html from your local machine to the remote server if the file exists in your local directory (or if you used the lcd command to change to the local directory where the file lives)

put "c:\websites\index.html"
Uploads the file index.html from a directory other than the current local directory connected to the FTP client

put *
Uploads all files from the current local directory to the present work directory on the remote server

Getting Files

The get command retrieves files from the remote server and places them in your current local directory. It works the same way as the put command. Remember to set the transfer mode before getting files.

get index.html
Downloads the file index.html to your local machine from the remote server

get images/backgrounds/stripes.png
Downloads the file stripes.png from the subdirectory of a subdirectory of the present working directory

get *.png
Downloads all files in the present working directory that have the .png extension

Closing and Quitting

When you have finished with the FTP client, first close the connection to the remote server by issuing the close command.

You can then type quit to exit the FTP client.

Command-Line Arguments

Like most command-prompt programs, the FTP client accepts arguments when it is invoked. In other words, you can attach more information to the command used to start the FTP client. This information can include the name of the server you want to connect to.

For example, entering the following line at the Command Prompt:

ftp troybrophy.com

will open the FTP client, and immediately connect to the remote server troybrophy.com.

For a complete list of arguments that FTP will accept, start the client and type help.