FTP Client


ftp


Red Hat supplies several FTP clients including ftp (an older version of the BSD ftp utility). This section discusses ftp because most other FTP clients provide a superset of ftp commands.

sftp


Part of the OpenSSH suite, sftp is a secure alternative to ftp. See page 589 for more information.

gftp


The gftp utility (gftp package) is a graphical client that works with FTP, SSH, and HTTP servers. This client has many useful features, including the ability to resume an interrupted file transfer. See the gftp man page for more information.

ncftp


The ncftp utility (ncftp package) is a textual client that offers many more features than ftp, including filename completion and command line editing. See the ncftp man page for details.

Prerequisites

The ftp and sftp utilities are installed on most Red Hat systems. You can check for their presence by giving either of these utilities' names as commands:

$ ftp ftp> quit


$ sftp usage: sftp [-1Cv] [-B buffer_size] [-b batchfile] [-F ssh_config]             [-o ssh_option] [-P sftp_server_path] [-R num_requests]             [-S program] [-s subsystem | sftp_server] host        sftp [[user@]host[:file [file]]]        sftp [[user@]host[:dir[/]]]        sftp -b batchfile [user@]host


Install the ftp or openssh-clients (contains sftp) package if needed.

JumpStart: Downloading Files Using ftp

This JumpStart section is broken into two parts: a description of the basic commands and a tutorial session that shows a user working with ftp.

Basic Commands

Give the command

$ ftp hostname


where hostname is the name of the FTP server you want to connect to. If you have an account on the server, log in with your username and password. If it is a public system, log in as the user anonymous (or ftp) and give your email address as your password. Use the ls and cd ftp commands on the server as you would use the corresponding utilities from a shell. The command get file copies file from the server to the local system, put file copies file from the local system to the server, status displays information about the FTP connection, and help displays a list of commands.

The preceding instructions, except for status, also work from sftp and ncftp.

Tutorial Session

Following are two ftp sessions wherein Alex transfers files from and to a vsftpd server named bravo. When Alex gives the command ftp bravo, the local ftp client connects to the server, which asks for a username and password. Because he is logged in on his local system as alex, ftp suggests that Alex log in on bravo as alex. To log in as alex, he could just press RETURN. Because his username on bravo is watson, however, he types watson in response to the Name (bravo:alex): prompt. Alex responds to the Password: prompt with his normal system password, and the vsftpd server greets him and informs him that it is Using binary mode to transfer files. With ftp in binary mode, Alex can transfer ASCII and binary files (page 608).

Connect and log in


$ ftp bravo Connected to bravo. 220 (vsFTPd 2.0.4) 530 Please login with USER and PASS. 530 Please login with USER and PASS. KERBEROS_V4 rejected as an authentication type Name (bravo:alex): watson 331 Please specify the password. Password: 230 Login successful. Remote system type is UNIX. Using binary mode to transfer files. ftp>


After logging in, Alex uses the ftp ls command to see what is in his remote working directory, which is his home directory on bravo. Then he cds to the memos directory and displays the files there.

ls and cd


ftp> ls 227 Entering Passive Mode (192,168,0,6,79,105) 150 Here comes the directory listing. drwxr-xr-x    2 500      500          4096 Oct 10 23:52 expenses drwxr-xr-x    2 500      500          4096 Oct 10 23:59 memos drwxrwxr-x   22 500      500          4096 Oct 10 23:32 tech 226 Directory send OK. ftp> cd memos 250 Directory successfully changed. ftp> ls 227 Entering Passive Mode (192,168,0,6,114,210) 150 Here comes the directory listing. -rw-r--r--    1 500      500           4770 Oct 10 23:58 memo.0514 -rw-r--r--    1 500      500           7134 Oct 10 23:58 memo.0628 -rw-r--r--    1 500      500           9453 Oct 10 23:58 memo.0905 -rw-r--r--    1 500      500           3466 Oct 10 23:59 memo.0921 -rw-r--r--    1 500      500           1945 Oct 10 23:59 memo.1102 226 Directory send OK.


Next Alex uses the ftp get command to copy memo.1102 from the server to the local system. Binary mode ensures that he will get a good copy of the file regardless of whether it is binary or ASCII. The server confirms that this file was copied successfully and reports on the size of the file and how long it took to copy. Alex then copies the local file memo.1114 to the remote system. The file is copied into his remote working directory, memos.

get and put


ftp> get memo.1102 local: memo.1102 remote: memo.1102 227 Entering Passive Mode (192,168,0,6,194,214) 150 Opening BINARY mode data connection for memo.1102 (1945 bytes). 226 File send OK. 1945 bytes received in 7.1e-05 secs (2.7e+04 Kbytes/sec) ftp> put memo.1114 local: memo.1114 remote: memo.1114 227 Entering Passive Mode (192,168,0,6,174,97) 150 Ok to send data. 226 File receive OK. 1945 bytes sent in 2.8e-05 secs (6.8e+04 Kbytes/sec)


Now Alex decides he wants to copy all the files in the memo directory on bravo to a new directory on his local system. He gives an ls command to make sure he will copy the right files, but ftp has timed out. Instead of exiting from ftp and giving another ftp command from the shell, he gives ftp an open bravo command to reconnect to the server. After logging in, he uses the ftp cd command to change directories to memos on the server.

Timeout and open


ftp> ls No control connection for command: Bad file descriptor Passive mode refused. Turning off passive mode. No control connection for command: Bad file descriptor ftp> open bravo Connected to bravo (192.168.0.6). 220 (vsFTPd 1.1.3) ... ftp> cd memos 250 Directory successfully changed.


Local cd (lcd)


At this point, Alex realizes he has not created the new directory to hold the files he wants to download. Giving an ftp mkdir command would create a new directory on the server, but Alex wants a new directory on his local system. He uses an exclamation point (!) followed by a mkdir memos.hold command to invoke a shell and run mkdir on the local system, creating a directory named memos.hold in his working directory on the local system. (You can display the name of your working directory on the local system with !pwd.) Next, because Alex wants to copy files from the server to the memos.hold directory on his local system, he has to change his working directory on the local system. Giving the command !cd memos.hold will not accomplish what Alex wants to do because the exclamation point will spawn a new shell on the local system and the cd command would be effective only in the new shell, which is not the shell that ftp is running under. For this situation, ftp provides the lcd (local cd) command, which changes the working directory for ftp and reports on the new local working directory:

ftp> !mkdir memos.hold ftp> lcd memos.hold Local directory now /home/alex/memos.hold


Alex uses the ftp mget (multiple get) command followed by the asterisk (*) wildcard to copy all files from the remote memos directory to the memos.hold directory on the local system. When ftp prompts him for the first file, Alex realizes that he forgot to turn off prompts, so he responds with n and presses CONTROL-C to stop copying files in response to the second prompt. The server checks whether he wants to continue with his mget command.

Next Alex gives the ftp prompt command, which toggles the prompt action (turns it off if it is on and turns it on if it is off). Now when he gives a mget * command, ftp copies all the files without prompting him. After getting the desired files, Alex gives a quit command to close the connection with the server, exit from ftp, and return to the local shell prompt.

mget and prompt


ftp> mget * mget memo.0514? n mget memo.0628? CONTROL-C Continue with mget? n ftp> prompt Interactive mode off. ftp> mget * local: memo.0514 remote: memo.0514 227 Entering Passive Mode (192,168,0,6,53,55) 150 Opening BINARY mode data connection for memo.0514 (4770 bytes). 226 File send OK. 4770 bytes received in 8.8e-05 secs (5.3e+04 Kbytes/sec) local: memo.0628 remote: memo.0628 227 Entering Passive Mode (192,168,0,6,65,102) 150 Opening BINARY mode data connection for memo.0628 (7134 bytes). 226 File send OK. ... 150 Opening BINARY mode data connection for memo.1114 (1945 bytes). 226 File send OK. 1945 bytes received in 3.9e-05 secs (4.9e+04 Kbytes/sec) ftp> quit 221 Goodbye.


Notes

A Linux system running ftp can exchange files with any of the many operating systems that support FTP. Many sites offer archives of free information on an FTP server, although for many it is just an alternative to an easier-to-access Web site (see, for example, ftp://ftp.ibiblio.org/pub/Linux and http://www.ibiblio.org/pub/Linux). Most browsers can connect to and download files from FTP servers.

The ftp utility makes no assumptions about filesystem naming or structure because you can use ftp to exchange files with non-UNIX/Linux systems (which may use different filenaming conventions).

Anonymous FTP

Many systemsmost notably those from which you can download free softwareallow you to log in as anonymous. Most systems that support anonymous logins accept the name ftp as an easier-to-spell and quicker-to-enter synonym for anonymous. An anonymous user is usually restricted to a portion of a filesystem set aside to hold files that are to be shared with remote users. When you log in as an anonymous user, the server prompts you to enter a password. Although any password may be accepted, by convention you are expected to supply your email address. Many systems that permit anonymous access store interesting files in the pub directory. Most browsers, such as Firefox, log in on an anonymous FTP site and transfer a file when you click on the filename.

Automatic Login

You can store server-specific FTP username and password information so that you do not have to enter it each time you visit an FTP site. Each line of ~/.netrc identifies a server. When you connect to an FTP server, ftp reads the ~/.netrc file to determine whether you have an automatic login set up for that server. The format of a line in ~/.netrc is


machine server login username password passwd

where server is the name of the server, username is your username, and passwd is your password on server. Replace machine with default on the last line of the file to specify a username and password for systems not listed in ~/.netrc. The default line is useful for logging in on anonymous servers. A sample ~/.netrc file follows:

$ cat ~/.netrc machine bravo login alex password mypassword default login anonymous password alex@tcorp.com


To protect the account information in .netrc, make it readable by only the user whose home directory it appears in. Refer to the netrc man page for more information.

Binary Versus ASCII Transfer Mode

The vsftpd FTP server canbut does not alwaysprovide two modes to transfer files. Binary mode transfers always copy an exact, byte-for-byte image of a file and never change line endings. Transfer all binary files using binary mode. Unless you need to convert line endings, use binary mode to transfer ASCII files as well.

ASCII files, such as text or program source code, when created under Linux with a text editor such as vi, use a single NEWLINE character (CONTROL-J, written as \n) to mark the end of each line. Other operating systems mark the ends of lines differently. Windows marks the end of each such line with a RETURN (CONTROL-M, written as \r) followed by a NEWLINE (two characters). Macintosh uses a RETURN by itself. These descriptions do not apply to files created by word processors such as Word or OpenOffice because those programs generate binary files.

The vsftpd FTP server can map Linux line endings to Windows line endings as you upload files and Windows line endings to Linux line endings as you download files. Although you could argue that these features should be on the client and not the server, they are incorporated in vsftpd, where the ASCII download feature can be a security risk.

To use ASCII mode on an FTP server that allows it, give an ascii command (page 610) after you log in and set cr to ON (the default, page 610). If the server does not allow you to change line endings as you transfer a file, you can use the unix2dos (page 139) or dos2unix (page 139) utility before or after you transfer a file in binary mode.

Security


When run against a very large file, the ftp size command, which displays the size of a file, consumes a lot of server resources and can be used to initiate a DoS attack (page 1030). To enhance security, by default vsftpd transfers every file in binary mode, even when it appears to be using ASCII mode. On the server side, you can enable real ASCII mode transfers by setting the ascii_upload_enable and ascii_download_enable parameters (page 619) to YES. With the server set to allow ASCII transfers, the client controls whether line endings are mapped by using the ascii, binary, and cr commands (page 610).

ftp Specifics

This section covers the details of using ftp.

Format

An ftp command line has the following format:


ftp [options][ftp-server]

where options is one or more options from the list in the next section and ftp-server is the name or network address of the FTP server that you want to exchange files with. If you do not specify an ftp-server, you will need to use the ftp open command to connect to a server once ftp is running.

Command Line Options

g


(globbing) Turns off globbing. See glob (page 610).

i


(interactive) Turns off prompts during file transfers with mget (page 610) and mput (page 610). See also prompt (page 611).

n


(no automatic login) Disables automatic logins (page 607).

v


(verbose) Tells you more about how ftp is working. Responses from the remote computer are displayed, and ftp reports information on how quickly files are transferred. See also verbose (page 612).

ftp Commands

The ftp utility is interactive: After you start ftp, it prompts you to enter commands to set parameters or transfer files. You can abbreviate commands as long as the abbreviations are unique. Enter a question mark (?) in response to the ftp> prompt to display a list of commands. Follow the question mark by a SPACE and a command to display a brief description of what the command does:

ftp> ? mget mget          get multiple files


Shell Command

![command]


Without command, escapes to (spawns) a shell on the local system. Use CONTROL-D or exit to return to ftp when you are finished using the local shell. Follow the exclamation point with command to execute that command only; ftp displays an ftp> prompt when execution of the command finishes. Because the shell that ftp spawns with this command is a child of the shell that is running ftp, no changes you make in this shell are preserved when you return to ftp. Specifically, when you want to copy files to a local directory other than the directory that you started ftp from, you need to use the ftp lcd command to change your local working directory: Issuing a cd command in the spawned shell will not make the change you desire. See "Local cd (lcd)" on page 606 for an example.

Transfer Files

In the following descriptions, remote-file and local-file can be pathnames.

append local-file [remote-file]


Appends local-file to the file of the same name on the remote system or to remote-file if specified.

get remote-file [local-file]


Copies remote-file to the local system under the name local-file. Without local-file, ftp uses remote-file as the filename on the local system.

mget remote-file-list


(multiple get) Copies several files to the local system, each maintaining its original filename. You can name the remote files literally or use wildcards (see glob). Use prompt (page 611) to turn off prompts during transfers.

mput local-file-list


(multiple put) Copies several files to the server, each maintaining its original filename. You can name the local files literally or use wildcards (see glob). Use prompt (page 611) to turn off prompts during transfers.

newer remote-file [local-file]


If the modification time of remote-file is more recent than that of local-file or if local-file does not exist, copies remote-file to the local system under the name local-file. Without local-file, ftp uses remote-file as the filename on the local system. Similar to get, but does not overwrite a newer file with an older one.

put local-file [remote-file]


Copies local-file to the remote system under the name remote-file. Without remote-file, ftp uses local-file as the filename on the remote system.

reget remote-file [local-file]


If local-file exists and is smaller than remote-file, assumes that a previous get of local-file was interrupted and continues from where the previous get left off. This command can save time when a get of a large file fails partway through the transfer.

Status

ascii


Sets the file transfer type to ASCII. The cr command must be ON for ascii to work (page 608).

binary


Sets the file transfer type to binary (page 608).

bye


Closes the connection to the server and terminates ftp. Same as quit.

case


Toggles and displays case mapping status. Default is OFF. When ON, for get and mget commands, maps filenames that are all uppercase on the server to all lower-case on the local system.

close


Closes the connection to the server without exiting from ftp.

cr


(carriage RETURN) Toggles and displays (carriage) RETURN stripping status. Effective only when the file transfer type is ascii. Set cr to ON (default) to remove RETURN characters from RETURN/LINEFEED line termination sequences used by Windows, yielding the standard Linux line termination of LINEFEED. Set cr to OFF to leave line endings unmapped (page 608).

debug [n]


Toggles/sets and displays debugging status/level, where n is the debugging level. OFF or 0 (zero) is the default. When n > 0, displays each command ftp sends to the server.

glob


Toggles and displays filename expansion (page 221) status for mdelete (page 611), mget (page 610), and mput (page 610) commands.

hash


Toggles and displays pound sign (#, also called a hash mark) display status. When ON, ftp displays one pound sign for each 1024-byte data block it transfers.

open [hostname]


Specifies hostname as the name of the server to connect to. Without hostname, prompts for the name of the server. Useful when a connection times out or otherwise fails.

passive


Toggles between active (PORTthe default) and passive (PASV) transfer modes and displays the transfer mode. For more information refer to "Passive versus active connections" on page 602.

prompt


Toggles and displays the prompt status. When ON (default), mdelete (page 611), mget (page 610), and mput (page 610) ask for verification before transferring each file. Set to OFF to turn off these prompts.

quit


Closes the connection to the server and terminates ftp. Same as bye.

umask [nnn]


Changes the umask (page 420) applied to files created on the server to nnn. Without nnn, displays the umask.

user [username] [password]


Prompts for or accepts the username and password that enable you to log in on the server. When you call it with the n option, ftp prompts you for a username and password automatically. For more information refer to "Automatic Login" on page 607.

Directories

cd remote-directory


Changes the working directory on the server to remote-directory.

cdup


Changes the working directory on the server to the parent of the working directory.

lcd[local_directory]


(local change directory) Changes the working directory on the local system to local_directory. Without an argument, this command changes the working directory on the local system to your home directory (just as the cd shell builtin does without an argument). See "Local cd (lcd)" on page 606 for an example.

Files

chmod mode remote-file


Changes the access permissions of remote-file on the server to mode. See chmod on page 182 for more information on how to specify the mode.

delete remote-file


Removes remote-file from the server.

mdelete remote-file-list


(multiple delete) Deletes the files specified by remote-file-list from the server.

Display Information

dir[remote-directory][file]


Displays a listing of remote-directory from the server. When you do not specify remote-directory, displays the working directory. When you specify file, the listing is saved on the local system in a file named file.

help[command]


Displays information about command. Without command, displays a list of local ftp commands.

ls[remote-directory][file]


Similar to dir but produces a more concise listing from some servers. When you specify file, the listing is saved on the local system in a file named file.

pwd


Displays the pathname of the working directory on the server. Use !pwd to display the pathname of the local working directory.

status


Displays ftp connection and status information.

verbose


Toggles and displays verbose mode, which displays responses from the server and reports on how quickly files are transferred. Same as specifying the v option on the command line.




A Practical Guide to Red Hat Linux
A Practical Guide to Red HatВ® LinuxВ®: Fedoraв„ў Core and Red Hat Enterprise Linux (3rd Edition)
ISBN: 0132280272
EAN: 2147483647
Year: 2006
Pages: 383

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net