Transferring Files Between Computers with FTP
This document explains how to transfer files between computers connected via the File Transfer Protocol (FTP) software. The transfer must be done while FTP or sFTP is running on the computer you are working on, and the "remote" computer you are using must also have FTP or sFTP available. Please note that the exact messages you receive depends on what version of FTP you are using, although they will be similar to those shown here. There is more information on FTP and sFTP in FTP File Transfer.
What is Needed to Use FTP or sFTP
Files can be transferred between a pair of machines with FTP or sFTP software, given that:
The machine you are using, the "local host machine", is running FTP or sFTP and is attached to the Internet computer network.
The machine you are attaching to, the "remote host machine", is running FTP or sFTP and is attached to the Internet computer network.
You know the Internet node name, also known as domain name (which generally has the form system.unit.institution.domain) , of the remote host machine. You may also use the remote host machine's Internet IP address (which has the form nnn.nnn.nnn.nnn, where nnn is a number between 0 and 255), but please be aware that this can and does change from time to time.
You have an active account on both the local and remote host machines, and you know the accounts' password (where relevant). (There are some "server" type machines whose purpose is to distribute files to the public which run "anonymous FTP" on which the logon id is "anonymous" and the password can be anything, but usually they ask you to use your own userid. Anyone can use these accounts.)
Commands Used to Transfer Files
All the commands in the examples are given in lowercase. Most computer systems, including Unix, are case sensitive; these case sensitive machines expect the FTP commands in lower case. Thus it is wisest to enter all FTP commands in lower case. The only exception is the names used to identify the files you are transferring, which should be entered in whatever case is used (or is to be used) when that file is listed in your directory. See Warning on the case of FTP commands and Warning on the case of file names.
Examples of the commands used and the responses generated by the commands are given in this section. Please note that on each system, the syntax of the commands might differ. Read the documentation for the system you will be using, or contact the remote site's computer center for more information.
To perform a file transfer, use the following procedure:
- Logon to your "local host machine" (if necessary).
- Enter the command:
ftp machine_name
on your local machine. The machine_name is the Internet node name of the "remote host machine" you are contacting, and has the general format:
system.unit.institution.domain
For example, the Internet node name of tigger is:
tigger.cc.uic.edu
You will receive a response similar to:
220-FTPSERVE at machine_name, hh:mm:ss CST day mm/dd/yy
220 (Possibly more information about the system...)
machine_name username: - At the prompt, enter your logon id on the remote host machine. After you enter your logon id the system will respond:
331 Send password, please
machine_name password: - Enter the password for your account on the remote machine and the system will respond:
230 user_name logged in; working directory directory_name
where "user_name" is the logon id you used to logon to the remote machine, and "directory_name" is your default directory on the remote machine. Please note that your profile file is not executed when you connect to most machines using FTP. - To see a list of available FTP commands, enter the command at the FTP prompt:
?
or:
help
To get more information about an individual FTP command enter at the FTP prompt:
help cmdname
where cmdname is the name of the FTP command. - To see a list of files available in the working directory on the remote machine, enter the command:
dir
The results will look something like this:
200 Port request OK
125 List started OK
250 List completed successfully
...List of files in your working directory appears here... - To list the files on your local machine, there will be either a command or simply a character that you can type that will allow you to temporarily return from FTP to the operating system of your local machine. Check your manual for this key/command for your software. Once you are back in the local machine, enter the command you would normally use to get a list of your files. For example, if you are using FTP from a PC running DOS, you would enter the DOS dir command at the DOS prompt, or if you are using FTP on on a Unix machine, you would enter the Unix ls command.
- By default, FTP assumes the file being transferred is an ASCII file. If the file is not an ASCII file, for example, if it is an executable file, you need to tell FTP that the transfer is not ASCII. To do this, enter the command at the FTP prompt:
binary
(or, depending on the version of FTP you're using, the command used might be octet or image . Check the version of FTP on your local machine for the appropriate command.) This command will tell both machines that they will be doing a binary file transfer. These new settings will be in effect until they are reset back to ASCII. To do so, at the FTP prompt, enter the command:
ascii
Note that IBM mainframes use EBCDIC and not ASCII. There is normally an ebcdic command available. If not, you may use ascii. - When you issue the FTP command to connect to a remote host machine, a default working directory on the remote host machine is set. The FTP commands you enter affect this directory. To change the remote working directory, issue the command at the FTP prompt:
cd new_directory
where new_directory is the name of the directory on the remote machine you wish to use. Make sure that the new_directory you enter follows the proper directory name conventions for the system you are connected to. - To transfer a file from your machine to the remote machine, use the put command at the FTP prompt. For example:
put localfile remotefile
will send the file on the local host machine with the name localfile to the remote machine with the name remotefile. When the file's name consists of two or more parts separated by spaces, such as a CMS file identifier, the parts of the name should be separated by periods; for example:
fname.ftype.B1
(See also Duplicate file names and Selecting record format and record length for CMS.) - When transferring files from the remote machine to the local machine, files are saved in your current directory. To change the directory on the local machine, enter the command, at the FTP prompt:
lcd local_directory_name
where local_directory_name is the name of the directory on your local machine where you want the files stored. Use the same rules and formats for the local_directory_name as described for the cd command above. - To transfer a file from the remote machine to your local machine, use the get command at the FTP prompt:
get remotefile localfile
where remotefile and localfile, which are, respectively, are the name the file has on the remote machine and the name the file will have on the local machine. (See also Duplicate file names.) - FTP allows for multiple file transfers using pattern matching by using the mget and mput commands.
mget *.com
would take all the files with the extension or the filetype, of "com" and transfer them to the local machine, while
mput *.com
would take all the files with the extension or the filetype, of "com" and send them to the remote machine. In both cases, the file's name on the destination machine will be built from the file's original name. For both mput and mget, you will be asked to respond Y or N for each file that matches the pattern. If you do not want to go through this prompting process, you can disable PROMPT by entering the command at the FTP prompt:
prompt off
or:
toggle prompt
Check your version of FTP for the proper command. (See also Duplicate file names.) - To close the connection to the remote machine, enter the command at the FTP prompt:
quit
The quit command actually will do two things. First, it will issue a close command to close the session between your machine and the remote machine. The second command executed is quit. Therefore, if you wish to open another connection to a machine without leaving FTP, you can enter the command at the FTP prompt:
close
When your session is closed, you can then open a new one. To do this, you may use the command:
open machine_name
or:
connect machine_name
Check your version of FTP for the proper command.
Possible Error Messages
When you attempt to connect to a remote host, the connection may not be completed, even if you have used the correct host name. The following are some common messages you might see, along with an explanation of what they mean.
Unknown host:
The hostname you specified was not found, or does not exist. Check the spelling of the hostname and try again.
Foreign host did not respond within OPEN timeout:
Either the specified host does not support FTP, or the host is busy (or unavailable) and could not open a FTP connection. If you know that the host does have FTP services, try again at a later time. If you are not sure, you may want to try again and, if you still can not connect, you may want to contact the remote site for additional information.
Some Things to Keep in Mind When Using FTP
Warning on the case of FTP commands.
All the commands in the examples in this document are given in lowercase. Many computer systems, including all Unix machines, are case sensitive; these case sensitive machines expect the commands in lower case. Thus it is wisest to enter all FTP commands in lower case.
Warning on the case of file names.
The only exception to the advice to always use lower case for FTP commands are for the names used to identify the files you are transferring. To be safe, always enter the file names exactly as they are shown in the FTP dir command, i.e. if they are shown as lower, upper, or mixed case, type them exactly as they are listed.
You have only one "working directory" available on the remote host machine.
When you use the FTP command cd, it releases the previous working directory before attaching the new one.
Access mode for working directory.
Initially, the working directory on the remote machine may be attached in read/only mode, but is automatically changed to write when/if it is necessary.
Binary vs ASCII files.
There are two general types of files, text and binary. A text file is a straightforward file. If you look at the contents of a text file, you will be able to distinguish the characters and/or read it. Text files are also called ASCII files. A binary file will not make any sense if you try to look at it; it consists mostly of unprintable characters. Different applications call for different formats. Be sure you know which type of file is most appropriate for your needs before making the transfer. Archived or compressed files and all executable files require binary transfer. PostScript output files generally do not.
Duplicate file names:
Most versions of FTP will replace an existing copy of the file you are transferring if one exists without warning or asking if it is ok to do so. So take care. Or enter the FTP command: sunique
which instucts FTP to generate a unique file identifier for any file being transferred whose name duplicates an existing file. When such a name conflict exists, you will be notified of the name actually used for the transferred copy. sunique is a toggle; enter it again to turn the "store unique" feature off.