Q: How do I ftp?
A: From the OIT Help Desk
http://www.helpdesk.umd.edu/documentation/other/ftp.shtml#6
Using FTP on the OIT Unix System and WAM System
The OIT Unix cluster has both FTP client and server software, so file transfers to and from the Unix cluster can be initiated either on the cluster and WAM systems themselves or on another computer system with client server software.
Connecting to Another System with FTP
To connect to another system using the Unix FTP client program, at the system prompt type:
- ftp other-machine-name
For example, if you wanted to transfer files to/from your Unix account to your account on the UMDD system, you would type:
- ftp umdd.umd.edu
The above example will connect you to a remote system called umdd.umd.edu. Once the connection is made, you login using your login-id (or user-id) and password for the remote system. Be sure to press Return following the entry of each. Following these two entries, your prompt will change to ftp> and you can begin transferring files.
The dialog below is an example of what you would see when connecting from one system to another. Notations regarding the dialog are on the right.
% ftp wam.umd.edu Specify the name of the system that you are attempting to connect to. Connected to wam.umd.edu. 230 racX.wam.umd.edu FTP server (Version wu-2.4(13) Wed Apr 19 15:25:29 EDT 1995) ready. Name (wam:username): jsmith Type your login-id for the remote system. 331 Password required for jsmith: Type your password for the remote system; Password: it will not appear. 230 User jsmith logged in. Once you successfully login, you will ftp> receive the FTP prompt.
If the login process fails, exit the FTP program by typing bye and try again. If you continue to have problems in establishing your FTP connection, contact the OIT Help Desk (OIT, CSS building, room 1400).
- Note: When FTPing to another system, you must have an account and password on that system, unless it is an anonymous FTP site (see Anonymous FTP).
Binary or ASCII?
Before you begin a transfer, you should decide whether the file should be transferred as an ASCII file or a binary file. An ASCII file is a text file (e.g., files created with a text editor). A binary file is a file with a special format unlike most text files. Binary files contain non-readable characters. Some common examples of binary files are program files, bit-mapped graphic image files (e.g., .gif, jpeg files) and most word processing/spreadsheet/database files. Binary files can be transferred safely as ASCII files when they have been encoded into readable characters for transfer through e-mail. Some common examples of these encoded files are Unix and PC uuencode files and also Macintosh BinHex (i.e., .hqx) files.
To avoid destroying binary files in transit, you must set FTP to binary mode by typing binary (or just bin) at the ftp> prompt. To set the transfer mode back to the default ASCII mode, type ascii at the ftp> prompt.
Transferring Files with put
To transfer a file from your Unix account (the local system) to the other system (the remote system), use the put command. The put command will transfer one file each time you use the command. To transfer multiple files, use the mput command as discussed in the next section.
To transfer a file with the put command, type any of the commands shown below at the ftp> prompt with local-file as the name of the file on the local system that you want to transfer and remote-file as the name you want the file to have on the remote system transfer.
ftp> put local-file remote-file This format specifies both filenames. ftp> put local-file This format specifies the assignment of the local filename on both local and remote systems. Note: Some remote systems will not accept this format. ftp> put This format will prompt you for the local (local-file) local-file filename first followed by the remote filename. (remote-file) remote-file
If the file you choose to transfer is not in the current directory, you must specify the directory path (including the name of the file) when prompted for the local file. You could also use the cd (change directory) command to move to the specific location of your file. (Refer to ftp command listing under Getting Help.)
The FTP program will display messages indicating that the file is being transferred. When the transfer is complete, FTP will display a message stating that the transfer was successful. The FTP program will display the file name on both the local and remote systems, the file size, and the transfer time of the file. The dialog below is an example of what you would see when transferring a local file (prog1.c) to a remote system and establishing the name of the remote file (squares.c) upon transfer.
- ftp> put
(local-file) prog1.c
(remote-file) squares.c
200 PORT command successful.
150 Opening data connection for login (128.8.10.20,3736).
226 Transfer complete.
local: prog1.c remote: squares.c
3794 bytes sent in 0.1 seconds (37 Kbytes/s)
ftp>
Transferring Files with get
To transfer a file with the get command, use get in the same manner you would use put except that the entry for the local-file and remote-file are reversed:
ftp> get remote-file local-file This format specifies both filenames. ftp> get remote-file This format specifies the assignment of the local filename on both local and remote systems.
Again, get will allow you to transfer only one file each time you use the command. (Use mget, described in Transferring Multiple Files with mput and mget, for multiple file transfers.) The dialog below is an example of what you would see when transferring a remote file (test.fortran) to your local system and assigning the local file a name (test.f).
- ftp> get
(remote-file) test.fortran
(local-file) test.f
The get command uses the same output display pattern of its counterpart (the put command). So again, when you use the get command, the FTP program will display several messages indicating the initiation and completion of the file transfer as well as the filenames, the file size and the transfer time.
- Important note: If the local-file name you've specified already exists on your account, it will be overwritten (replaced) by the remote-file with no warning!
Transferring Multiple Files with mput and mget
It is also possible to transfer several files at one time using the mget (multiple get) and mput (multiple put) commands.
These commands work in the same manner as get and put, but you don't specify a name for the files on the destination machine. They keep their names or are modified to match the naming requirements of the destination machine.
To transfer multiple files from your Unix account to the other remote system, enter the mput command followed by your local files:
- mput local-files
For example, if you have two files given the names file1 and file2, type:
- mput file1 file2
You must confirm the transfer of both file1 and file2 to the remote system. You can type y (yes) to verify this file transfer or n (no) if you do not want to transfer the specified file to the remote system.
Using Unix Wildcard Characters
You can also use Unix wildcard characters to transfer multiple files easily. The most common wildcard characters used for this purpose are the asterisk (*) and the question mark (?).
* matches zero or more characters; for example, *.f will match all files ending with the .f pattern, including: prog1.f, prog.f and .f ? matches a single character. For example, file.? will match all files starting with file. followed by a single character, including: file.f and file.a ( but not file.output)
So, if you choose to transfer prog1.f, file.f and other files ending in the .f pattern, type:
- mput *.f
The mget command can be used in the same manner. To transfer files from the remote system to your local Unix system, type mget followed by your remote files:
- mget remote-files
When using both mput and mget, you are prompted to verify that you choose to transfer each individual file. When you use either command, type y (yes) if you want to transfer the file or type n (no) if you don't want to transfer the file.
If you want to bypass the verification feature and transfer all of your files without having to respond with y or n, turn off this feature by typing prompt at the ftp> prompt. If you deactivate this feature and later choose to reactivate it, just type prompt again.
Listing Files and Changing Directories
To get a listing of the files on the remote system, use the ls and dir commands. The ls command displays a listing of all of the files in the current directory on the remote system. The dir command displays more detailed information about the files on the remote system, including file size, file modification date, and other information. This display of information, including file ownership, permissions, and format, varies from system to system.
If you use ls to display a list of files in the directory you're currently in on the remote system and the list is long, the display will scroll forward rapidly. To pause the display listing type:
- ls . |more
Do not space after the pipe (|) symbol. This command will display a list of files one screen at a time. Additional commands are available for you to use following entry of the ls command:
(Spacebar) to display the next screen (Return) to display the next line (q) to end the display
You can also use this same technique to examine the contents of a plain or text file. For example, to display the contents of a README file on a remote system, type:
- get README |more
The pwd command displays the present working directory on the remote system. The cd command is used to change directories on the remote system if you want to transfer files to or from a subdirectory. For example, to change to the proj1 directory on the remote system, type:
- cd proj1
To change directories locally (on your Unix account) use the lcd command; type:
- lcd cmsc330
If, while still in the FTP program, you find you need to execute a Unix command on your local account, prefix the command with an exclamation mark (!). So, if you forget what directory you're in on your local Unix account or you want a list of your local files, type:
- !pwd
The !ls command will give you a listing of the files in the current directory on your Unix account (local system) without quitting the FTP program. The !mv command can also be used to rename local files that conflict with files being transferred to your local system by way of the mget command.
Quitting the FTP Program
When you have completed the process of transferring files, you can exit the Unix FTP program by typing quit or bye.