Great Templates

FEATURED WEB TEMPLATES

Amazon Books

Learn PHP

PHP Training
Zend Cert Training Zend Certified Engineer Zend PHP Pro

FTP File Transfer Protocol: FTP Commands

General Information about FTP Commands

When an FTP connection is established between two computers, the computer acting as the client issues specific commands to the computer acting as the server. Many of these commands are similar to basic file manipulation commands used in the UNIX operating system. In some cases, the user will type in commands directly, which the FTP client software will interpret and send to the remote computer. These commands vary somewhat depending on the particular software being used; Table 1 at the end of this article summarizes some of the most commonly used commands. With some FTP client software, users do not need to enter these commands; instead, the client software will send the appropriate commands to the FTP server when the user chooses an item from a menu or clicks on a button, for instance. Most ftp clients are command-oriented and many of the common commands are the same regardless of the platform or operating system. Some commands are executed without any arguments or parameters and some have optional or required arguments.

Abbreviations : The abbreviations listed below are used throughout this guide as variables to refer to local and remote directory and file names.

Variable Name Meaning
ldirname local directory name
rdirname remote directory name
lfilename local filename
rfilename remote filename

Upper versus Lower Case. Remember that UNIX file and directory names are case-sensitive. When referring to a file or directory on a UNIX system within an ftp command, type the name EXACTLY as it is displayed with a dir or ls command.

Wild cards. When writing out filenames, wild cards can be used to display or transfer multiple files. A wild card is a special character (or group of characters) that substitutes for one or more characters in a file or directory name. The most common wil card is the asterisk (*). The * represents any series of adjacent characters in a filename. The * is helpul when you want to list all of the files that start or end with the same few letters. Here are some examples of how the * can be used:

Example Explanation
read* Represents all filenames that begin with the string "read", including names like readme.doc, readmeandweep, and read.
*html* Represents all filenames containing the string "html" anywhere in the filename, including names like html-viewer-111.hqx, index.html, and text-to-html-131.hqx.
*txt Represents all filenames that end with the string "txt", including names like abstract.txt and readme.txt.

Commands for Opening a Session

Command Syntax Command Description
ftp fully.qualified.domain.name Open an ftp session with the specified host. You will be prompted to enter a userid (login name) and password.

Examples:

ftp ftp.cso.uiuc.edu
ftp boombox.micro.umn.edu

ftp Start the ftp client without opening a session with a remote host. Normally, this command will get you to an ftp> prompt.
open fully.qualified.domain.name Open an ftp session with the specified host from the ftp> prompt.
user your_loginname Tell the remote host the login name of the account you will be using. Normally you will be prompted for this information when you connect to the remote host. If you enter your login name incorrectly, you can use this command to enter the correct information.

Examples:

user ward
user anonymous

Commands for Closing a Session

Command Syntax Command Description
quit Close the current session and quit ftp client. You will be returned to the operating system prompt.
close Close the current session without quitting the ftp client. You will be returned to the ftp> prompt and can use the open command to open a new session.

Commands for Displaying the Contents of a Directory

Command Syntax Command Description
ls Display (list) the contents of the current directory on the remote host.
ls rdirname Display the contents of the specified directory on the remote host

Example:

ls /pub/pc

ls rfilenames Display the specified files/directories on the remote host.

Examples:

ls read*
ls *.txt

dir Display (list) the contents of the current directory on the remote host in long (verbose) format. This command shows the permissions, size, date, owner and group names, etc. for each file in the list.
dir rdirname Display the contents of the specified directory on the remote host in long format.

Example:

dir /pub/pc

dir rfilenames Display the specified files on the remote host in long format.

Examples:

dir read*
dir *.txt

Commands for Changing Directory on the Remote or Local Host

Command Syntax Command Description
cd rdirname Change to the specified directory on the remote host. When changing directories on a Macintosh, surround the directory name with quotation marks.

Examples:

cd /pub
cd pub
cd /pub/mac/Eudora
cd "/My HD/net /telnet 2.5"

lcd ldirname Change to the specified directory on the local host. When changing directories on a Macintosh, surround the directory name with quotation marks.

Examples:

lcd /pub
lcd pub
lcd /pub/mac/Eudora
lcd "/My HD/net /telnet 2.5"

pwd Display the name of the current directory on the remote host.

Commands for Specifying Transfer Type

There are two modes for transferring files. Binary mode, which duplicates a file exactly, bit-for-bit, must be used when moving binary files, such as compiled programs, formatted data files (such as those produced by a commercial word processeor like WordPerfect or MS Word), archived files in most common compression formats (i.e., ZIP, ZOO, tar, etc.), graphics file, etc. If such files are not transferred in binary mode, they will not be useable. The ASCII transfer mode, on the other hand, should always be used when moving plain text files limited to the ASCII character set or other character sets (e.g., EBCDIC) mapped to decimal numbers 0-127. When a file is transferred in ASCII mode, the file is translated to the proper character set and line-endings for the target operating system. For example, when an ASCII file is transferred from a Macintosh to a UNIX system, carriage returns, which are the standard end-of-line characters for the Mac, are converted to line-feeds. Without this conversion, the file behaves as if it consists of a single, very long line. Command Syntax Command Description
ascii Set the file transfer mode to ASCII. Use ASCII mode for text files (.txt, .doc, .asc. etc.) postscript files (.ps), BinHexed files (.hqx), and uuencoded files (.uue).
binary Set the file transfer mode to binary. Use binary mode for most executable files (except shell scripts and batch files), formatted data files, and compressed files. Use MacBinary mode when moving Macintosh binary files to or from a non-Macintosh system.

Commands for Moving Files with FTP

There are two basic commands for moving files in ftp, get and put. The get command is used to move files from the server to the client and the put command is used to move files from the client to the server. Before executing a file transfer, remember to specify the transfer type (ascii or binary).

The put and get commands take two arguments, a source filename and a destination or target filename. The source filename must always be provided. If a target filename is not provided, the client will attempt to write the file to the target using the source filename. If target file system does not support all of the characters in the source filename, the name will automatically be modified to accommodate the target file system. For example, when moving files from a UNIX system to a PC running DOS, files with names longer than the the 8x3 DOS standard are truncated.

Command Syntax Command Description
get rfilename [lfilename] Move the specified file from the remote host to the local host.

Examples:

get readme.first
get readme.first readme.1st

mget rfilename(s) Move the specified files from the remote host to the local host. You will be asked to confirm the transfer for each file. To turn this interactive prompting off, enter the prompt command before executing the mget command.

Examples:

mget *.ZIP
mget nupop*
mget *

put lfilename [rfilename] Move the specified file from the local host to the remote host.

Examples:

put myfile.zip
put readme.1st AAREADME.FIRST

mput lfilename(s) Move the specified files from the local host to the remote host. You will be asked to confirm the transfer for each file. To turn this interactive prompting off, enter the prompt command before executing the mput command.

Examples:

mput *.ZIP
mput *

Miscellaneous FTP Commands

Command Syntax Command Description
! [command] Execute an operating system command on the local host. Entered by itself, ! will shell out to the operating system.

Examples:

! dir
! edit readme.txt
!

help Display a list of ftp commands.
help command Display help for the specified command.

Examples:

help ls
help put
help mdelete

prompt Toggle interactive mode on/off.

 


Learn PHP | Zend Certified Engineer | Zend PHP Pro | PHP Web Apps | Web Hosting Service | Low Cost Domain Names | Great Templates | Great Books | Testimonials | Tech.Articles | TOS | AUS | Home | Linux Apache MySQL PHP