Basic FTP Commands - Workshare's Weblog



Basic FTP Commands | |

| |

[pic]

[pic]

What is FTP?

The FTP (File Transfer Protocol) utility program is commonly used for copying files to and from other computers. These computers may be at the same site or at different sites thousands of miles apart. FTP is a general protocol that works on UNIX systems as well as a variety of other (non-UNIX) systems.

For the purposes of this Web page, the local machine refers to the machine you are initially logged into, the one on which you type the ftp command. The remote machine is the other one, the one that is the argument of the ftp command.

A user interface for the standard File Transfer Protocol for ARPANET, FTP acts as an interpreter on the remote machine. The user may type a number of UNIX-like commands under this interpreter to perform desired actions on the remote machine.

Most operating systems and communication programs now include some form of an FTP utility program, but the commands differ slightly between them. The following explanations and alphabetical list of commands refers to the common FTP utility program as provided on a UNIX machine. Check the documentation for your own machine to determine the comparable commands.

Most computers today include a windows-based type FTP program that is more PC-oriented and does not require full knowledge of these commands.

You can also perform FTP through a browser. For example, bring up Internet Explorer and type in

           

instead of a normal web page URL.

The FTP site of the Computer Science department at CSU requires the user to use sftp, the secure version of FTP. Just type sftp instead of ftp, when you are using FTP in a terminal window.

[pic]

Getting Started

To connect your local machine to the remote machine, type

            ftp machinename

where machinename is the full machine name of the remote machine, e.g., purcell.cs.colostate.edu. If the name of the machine is unknown, you may type

            ftp machinennumber

where machinennumber is the net address of the remote machine, e.g., 129.82.45.181. In either case, this command is similar to logging onto the remote machine. If the remote machine has been reached successfully, FTP responds by asking for a loginname and password.

When you enter your own loginname and password for the remote machine, it returns the prompt

            ftp>

and permits you access to your own home directory on the remote machine. You should be able to move around in your own directory and to copy files to and from your local machine using the FTP interface commands given on the following page.

[pic]

Anonymous FTP

At times you may wish to copy files from a remote machine on which you do not have a loginname. This can be done using anonymous FTP.

When the remote machine asks for your loginname, you should type in the word anonymous. Instead of a password, you should enter your own electronic mail address. This allows the remote site to keep records of the anonymous FTP requests.

Once you have been logged in, you are in the anonymous directory for the remote machine. This usually contains a number of public files and directories. Again you should be able to move around in these directories. However, you are only able to copy the files from the remote machine to your own local machine; you are not able to write on the remote machine or to delete any files there.

[pic]

Common FTP Commands

|? |to request help or information about the FTP commands |

|ascii |to set the mode of file transfer to ASCII |

| |(this is the default and transmits seven bits per character) |

|binary |to set the mode of file transfer to binary |

| |(the binary mode transmits all eight bits per byte and thus provides less chance of a transmission error and must be |

| |used to transmit files other than ASCII files) |

|bye |to exit the FTP environment (same as quit) |

|cd |to change directory on the remote machine |

|close |to terminate a connection with another computer |

|  |close brubeck |closes the current FTP connection with brubeck, |

| | |  but still leaves you within the FTP environment. |

|delete |to delete (remove) a file in the current remote directory (same as rm in UNIX) |

|get |to copy one file from the remote machine to the local machine |

|  |get ABC DEF |copies file ABC in the current remote directory to (or on top of) a file named DEF in your |

| | |current local directory. |

|  |get ABC |copies file ABC in the current remote directory to (or on top of) a file with the same name, |

| | |ABC, in your current local directory. |

|help |to request a list of all available FTP commands |

|lcd |to change directory on your local machine (same as UNIX cd) |

|ls |to list the names of the files in the current remote directory |

|mkdir |to make a new directory within the current remote directory |

|mget |to copy multiple files from the remote machine to the local machine; |

| |  you are prompted for a y/n answer before transferring each file |

|  |mget * |copies all the files in the current remote directory to your current local directory, using |

| | |the same filenames. Notice the use of the wild card character, *. |

|mput |to copy multiple files from the local machine to the remote machine; |

| |  you are prompted for a y/n answer before transferring each file |

|open |to open a connection with another computer |

|  |open brubeck |opens a new FTP connection with brubeck; |

| | |  you must enter a username and password for a brubeck account |

| | |      (unless it is to be an anonymous connection). |

|put |to copy one file from the local machine to the remote machine |

|pwd |to find out the pathname of the current directory on the remote machine |

|quit |to exit the FTP environment (same as bye) |

|rmdir |to to remove (delete) a directory in the current remote directory |

| | | |

[pic]

Further Information

Many other interface commands are available. Also FTP can be run with different options. Please refer to your manual or the UNIX man page on ftp for more information.

See also the SILS FTP Tutorial

[pic]

Example Sessions

Examples of two FTP sessions are given on the next two pages. These show the type of interaction you may expect when using the ftp utility.

[pic]

Example of Anonymous FTP Session

|% ftp cs.colorado.edu |

|Connected to cs.colorado.edu. |

|220 bruno FTP server (SunOS 4.1) ready. |

|Name (cs.colorado.edu:yourlogin): anonymous |

|331 Guest login ok, send ident as password. |

|Password: |

|230-This server is courtesy of Sun Microsystems, Inc. |

|230- |

|230-The data on this FTP server can be searched and accessed via WAIS, using |

|230-our Essence semantic indexing system. Users can pick up a copy of the |

|230-WAIS ".src" file for accessing this service by anonymous FTP from |

|230-ftp.cs.colorado.edu, in pub/cs/distribs/essence/aftp-cs-colorado-edu.src |

|230-This file also describes where to get the prototype source code and a |

|230-paper about this system. |

|230- |

|230- |

|230 Guest login ok, access restrictions apply. |

|ftp> cd /pub/HPSC |

|250 CWD command successful. |

|ftp> ls |

|200 PORT command successful. |

|150 ASCII data connection for /bin/ls (128.138.242.10,3133) (0 bytes). |

|ElementsofAVS.ps.Z |

|. . . |

|execsumm_tr.ps.Z |

|viShortRef.ps.Z |

|226 ASCII Transfer complete. |

|418 bytes received in 0.043 seconds (9.5 Kbytes/s) |

|ftp> get README |

|200 PORT command successful. |

|150 ASCII data connection for README (128.138.242.10,3134) (2881 bytes). |

|226 ASCII Transfer complete. |

|local: README remote: README |

|2939 bytes received in 0.066 seconds (43 Kbytes/s) |

|ftp> bye |

|221 Goodbye. |

|% ls |

|. . . |

|README |

|. . . |

| |

An FTP session to obtain the HPSC README file from the cs.colorado.edu anonymous ftp directory using a loginname of anonymous and a password of one's own electronic mail address.

[pic]

Example of Regular FTP Session

|% ftp nordsieck.cs.colorado.edu |

|Connected to nordsieck.cs.colorado.edu. |

|220 nordsieck FTP server (Version 5.53 Tue Aug 25 10:46:12 MDT 1992) ready. |

|Name (nordsieck.cs.colorado.edu:yourlogin): yourlogin |

|331 Password required for yourlogin. |

|Password: |

|230 User yourlogin logged in. |

|ftp> cd HPSC/exercises |

|250 CWD command successful. |

|ftp> ls |

|200 PORT command successful. |

|550 No files found. |

|ftp> put tmul.out |

|200 PORT command successful. |

|150 Opening ASCII mode data connection for tmul.out. |

|226 Transfer complete. |

|local: tmul.out remote: tmul.out |

|1882 bytes sent in 0.0095 seconds (1.9e+02 Kbytes/s) |

|ftp> ls |

|200 PORT command successful. |

|150 Opening ASCII mode data connection for file list. |

|tmul.out |

|226 Transfer complete. |

|9 bytes received in 0.0021 seconds (4.3 Kbytes/s) |

|ftp> mput * |

|mput Makefile? y |

|200 PORT command successful. |

|150 Opening ASCII mode data connection for Makefile. |

|226 Transfer complete. |

|local: Makefile remote: Makefile |

|1020 bytes sent in 0.0062 seconds (1.6e+02 Kbytes/s) |

|mput tmul.out? n |

|ftp> quit |

|221 Goodbye. |

|% ls |

|. . . |

|Makefile |

|tmul.out |

|. . . |

| |

An FTP session to copy files from a remote machine back to nordsieck.cs.colorado.edu using one's own login and password.

[pic]

List of FTP commands for the Microsoft command-line FTP client

Command-line options

As you're starting the program from a DOS prompt:

ftp [-v] [-d] [-i] [-n] [-g] [-s:filename] [-a] [-w:windowsize] [computer]

• -v - Suppresses verbose display of remote server responses.

• -n - Suppresses auto-login upon initial connection.

• -i - Turns off interactive prompting during multiple file transfers.

• -d - Enables debugging, displaying all ftp commands passed between the client and server.

• -g - Disables filename globbing, which permits the use of wildcard chracters in local file and path names.

• -s:filename - Specifies a text file containing ftp commands; the commands will automatically run after ftp starts. No spaces are allowed in this parameter. Use this switch instead of redirection (>).

• -a - Use any local interface when binding data connection.

• -w:windowsize - Overrides the default transfer buffer size of 4096.

• computer - Specifies the computer name or IP address of the remote computer to connect to. The computer, if specified, must be the last parameter on the line.

Client commands

• ! - Runs the specified command on the local computer

• ? - Displays descriptions for ftp commands

• append - Appends a local file to a file on the remote computer

• ascii - Sets the file transfer type to ASCII, the default

• bell - Toggles a bell to ring after each file transfer command is completed (default = OFF)

• binary - Sets the file transfer type to binary

• bye - Ends the FTP session and exits ftp

• cd - Changes the working directory on the remote computer

• close - Ends the FTP session and returns to the command interpreter

• debug - Toggles debugging (default = OFF)

• delete - Deletes a single file on a remote computer

• dir - Displays a list of a remote directory's files and subdirectories

• disconnect - Disconnects from the remote computer, retaining the ftp prompt

• get - Copies a single remote file to the local computer

• glob - Toggles filename globbing (wildcard characters) (default = ON)

• hash - Toggles hash-sign (#) printing for each data block transferred (default = OFF)

• help - Displays descriptions for ftp commands

• lcd - Changes the working directory on the local computer

• literal - Sends arguments, verbatim, to the remote FTP server

• ls - Displays an abbreviated list of a remote directory's files and subdirectories

• mdelete - Deletes one or more files on a remote computer

• mdir - Displays a list of a remote directory's files and subdirectories

• mget - Copies one or more remote files to the local computer

• mkdir - Creates a remote directory

• mls - Displays an abbreviated list of a remote directory's files and subdirectories

• mput - Copies one or more local files to the remote computer

• open - Connects to the specified FTP server

• prompt - Toggles prompting (default = ON)

• put - Copies a single local file to the remote computer

• pwd - Displays the current directory on the remote computer (literally, "print working directory")

• quit - Ends the FTP session with the remote computer and exits ftp (same as "bye")

• quote - Sends arguments, verbatim, to the remote FTP server (same as "literal")

• recv - Copies a remote file to the local computer

• remotehelp - Displays help for remote commands

• rename - Renames remote files

• rmdir - Deletes a remote directory

• send - Copies a local file to the remote computer (same as "put")

• status - Displays the current status of FTP connections

• trace - Toggles packet tracing (default = OFF)

• type - Sets or displays the file transfer type (default = ASCII)

• user - Specifes a user to the remote computer

• verbose - Toggles verbose mode (default = ON)

[pic]

!

Runs the specified command on the local computer.

Syntax: ! [command]

Parameter(s):

command - Specifies the command to run on the local computer. If command is omitted, the local command prompt is displayed; type "exit" to return to ftp.

?

Displays descriptions for ftp commands. ? is identical to help.

Syntax: ? [command]

Parameter(s):

command - Specifies the name of the command about which you want a description. If command is not specified, ftp displays a list of all commands.

append

Appends a local file to a file on the remote computer using the current file type setting.

Syntax: append local-file [remote-file]

Parameter(s):

local-file - Specifies the local file to add.

remote-file - Specifies the file on the remote computer to which local-file will be added. If remote-file is omitted, the local filename is used for the remote filename.

ascii

Sets the file transfer type to ASCII, the default.

Syntax: ascii

Note

FTP supports two file transfer types, ASCII and binary image. ASCII should be used when transferring text files. See also binary.

In ASCII mode, character conversions to and from the network standard character set are performed. For example, end-of-line characters are converted as necessary, based on the target operating system.

bell

Toggles a bell to ring after each file transfer command is completed. By default, the bell is off.

Syntax: bell

binary

Sets the file transfer type to binary.

Syntax: binary

Note

FTP supports two file transfer types, ASCII and binary image. Binary should be used when transferring executable files. In binary mode, the file is moved byte-by-byte. See also ascii.

bye

Ends the FTP session with the remote computer and exits ftp.

Syntax: bye

cd

Changes the working directory on the remote computer.

Syntax: cd remote-directory

Parameter(s):

remote-directory - Specifies the directory on the remote computer to change to.

close

Ends the FTP session with the remote server and returns to the command interpreter.

Syntax: close

debug

Toggles debugging. When debugging is on, each command sent to the remote computer is printed, preceded by the string --->. By default, debugging is off.

Syntax: debug

delete

Deletes a single file on a remote computer. See also mdelete, which can delete multiple files.

Syntax: delete remote-file

Parameter(s):

remote-file - Specifies the file to delete.

dir

Displays a list of a remote directory's files and subdirectories. See also mdir, which can list multiple directories.

Syntax: dir [remote-directory] [local-file]

Parameter(s):

remote-directory - Specifies the directory for which you want to see a listing. If no directory is specified, the current working directory on the remote computer is used.

local-file - Specifies a local file to store the listing. If not specified, output is displayed on the screen.

disconnect

Disconnects from the remote computer, retaining the ftp prompt.

Syntax: disconnect

get

Copies a remote file to the local computer using the current file transfer type. See also mget, which can copy multiple files.

Syntax: get remote-file [local-file]

Parameter(s):

remote-file

Specifies the remote file to copy.

local-file

Specifies the name to use on the local computer. If not specified, the file is given the remote-file name.

glob

Toggles filename globbing. Globbing permits use of wildcard characters in local file or path names. By default, globbing is on.

Syntax: glob

hash

Toggles hash-sign (#) printing for each data block transferred. The size of a data block is 2048 bytes. By default, hash mark printing is off.

Syntax: hash

help

Displays descriptions for ftp commands.

Syntax: help [command]

Parameter(s):

command - Specifies the name of the command about which you want a description. If command is not specified, ftp displays a list of all commands.

lcd

Changes the working directory on the local computer. By default, the working directory is the directory in which ftp was started.

Syntax: lcd [directory]

Parameter(s):

directory - Specifies the directory on the local computer to change to. If directory is not specified, the current working directory on the local computer is displayed.

literal

Sends arguments, verbatim, to the remote FTP server. A single FTP reply code is expected in return.

Syntax: literal argument [ ...]

Parameter(s):

argument - Specifies the argument to send to the FTP server.

ls

Displays an abbreviated list of a remote directory's files and subdirectories.

Syntax: ls [remote-directory] [local-file]

Parameter(s):

remote-directory - Specifies the directory for which you want to see a listing. If no directory is specified, the current working directory on the remote computer is used.

local-file - Specifies a local file to store the listing. If not specified, output is displayed on the screen.

mdelete

Deletes one or more files on a remote computer.

Syntax: mdelete remote-files [ ...]

Parameter(s):

remote-files - Specifies the remote files to delete.

mdir

Displays a list of a remote directory's files and subdirectories. Mdir allows you to specify multiple files.

Syntax: mdir remote-files [ ...] local-file

Parameter(s):

remote-files - Specifies the directory for which you want to see a listing. Remote-files must be specified; type "-" to use the current working directory on the remote computer.

local-file - Specifies a local file to store the listing. Type "-" to display the listing on the screen.

mget

Copies one or more remote files to the local computer using the current file transfer type.

Syntax: mget remote-files [ ...]

Parameter(s):

remote-files - Specifies the remote file(s) to copy to the local computer.

mkdir

Creates a remote directory.

Syntax: mkdir directory

Parameter(s):

directory - Specifies the name of the new remote directory.

mls

Displays an abbreviated list of a remote directory's files and subdirectories.

Syntax: mls remote-files [ ...] local-file

Parameter(s):

remote-files - Specifies the files for which you want to see a listing. Remote-files must be specified; type "-" to use the current working directory on the remote computer.

local-file - Specifies a local file to store the listing. Type "-" to display the listing on the screen.

mput

Copies one or more local files to the remote computer using the current file transfer type.

Syntax: mput local-files [ ...]

Parameter(s):

local-files - Specifies the local files to copy to the remote computer.

open

Connects to the specified FTP server.

Syntax: open computer [port]

Parameter(s):

computer - Specifies the remote computer to connect to. Computer can be specified by IP address or computer name (a DNS or HOSTS file must be available). If auto-login is on (default), FTP also attempts to automatically log the user in to the FTP server (see Ftp command-line options to disable auto-login).

port - Specifies a port number to use to contact an FTP server.

prompt

Toggles prompting. Ftp prompts during multiple file transfers to allow you to selectively retrieve or store files; mget and mput transfer all files if prompting is turned off. By default, prompting is on.

Syntax: prompt

put

Copies a local file to the remote computer using the current file transfer type. See also mput, which can copy multiple files.

Syntax: put local-file [remote-file]

Parameter(s):

local-file - Specifies the local file to copy.

remote-file - Specifies the name to use on the remote computer. If not specified, the file is given the local-file name.

pwd

Displays the current directory on the remote computer.

Syntax: pwd

quit

Ends the FTP session with the remote computer and exits ftp.

Syntax: quit

quote

Sends arguments, verbatim, to the remote FTP server. A single FTP reply code is expected in return. Quote is identical to literal.

Syntax: quote argument [ ...]

Parameter(s):

argument - Specifies the argument to send to the FTP server.

recv

Copies a remote file to the local computer using the current file transfer type. Recv is identical to get.

Syntax: recv remote-file [local-file]

Parameter(s):

remote-file - Specifies the remote file to copy.

local-file - Specifies the name to use on the local computer. If not specified, the file is given the remote-file name.

remotehelp

Displays help for remote commands.

Syntax: remotehelp [command]

Parameter(s):

command - Specifies the name of the command about which you want help. If command is not specified, ftp displays a list of all remote commands.

rename

Renames remote files.

Syntax: rename filename newfilename

Parameter(s):

filename - Specifies the file you want to rename.

newfilename - Specifies the new filename.

rmdir

Deletes a remote directory.

Syntax: rmdir directory

Parameter(s):

directory - Specifies the name of the remote directory to delete.

send

Copies a local file to the remote computer using the current file transfer type. Send is identical to put.

Syntax: send local-file [remote-file]

Parameter(s):

local-file - Specifies the local file to copy.

remote-file - Specifies the name to use on the remote computer. If not specified, the file is given the local-file name.

status

Displays the current status of FTP connections and toggles.

Syntax: status

trace

Toggles packet tracing; trace displays the route of each packet when running an ftp command.

Syntax: trace

type

Sets or displays the file transfer type.

Syntax: type [type-name]

Parameter(s):

type-name - Specifies the file transfer type; the default is ASCII. If type-name is not specified, the current type is displayed.

Note

FTP supports two file transfer types, ASCII and binary image.

ASCII should be used when transferring text files. In ASCII mode, character conversions to and from the network standard character set are performed. For example, end-of-line characters are converted as necessary, based on the destination's operating system.

Binary should be used when transferring executable files. In binary mode, the file is moved byte-by-byte.

user

Specifes a user to the remote computer.

Syntax: user user-name [password] [account]

Parameter(s):

user-name - Specifies a user name with which to log in to the remote computer.

password - Specifies the password for user-name. If not specified, but required, ftp prompts for the password.

account - Specifies an account with which to log on to the remote computer. If account is not specified, but required, ftp prompts for the account.

verbose

Toggles verbose mode. If on, all ftp responses are displayed; when a file transfer completes, statistics regarding the efficiency of the transfer are also displayed. By default, verbose is on.

Syntax: verbose

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download