Home » , , » Using FTP in Linux

Using FTP in Linux

Written By Sajib Barua on Sunday, August 19, 2012 | 9:21 AM

previous Reading Newsgroups and RSS Feeds in Linux
Just as the name implies, File Transfer Protocol (FTP) is used to transfer files between computers. For example, if your Internet service provider (ISP) gives you space for a personal Web site, you may have already used FTP to upload the files making up the Web site. Using an FTP client on your computer, you log in to your ISP account, provide your password, and then copy the files from your home system to the ISP’s server.
You can also use FTP to download other files anonymously, such as open source software from other computers on the Internet — in which case, you don’t need an account on the remote system to download files. You can simply log in using anonymous as the username and provide your e-mail address as the password. (In fact, your Web browser can do this on your behalf, so you may not even know this process is happening.) This type of anonymous FTP is great for distributing files to anyone who wants them. For example, a hardware vendor might use anonymous FTP to provide updated device drivers to anyone who needs them.
Linux comes with several FTP clients, both command-line ones and GUI (graphical user interface) ones. This chapter introduces you to a few GUI FTP clients and a command-line FTP client. It also describes the commands you use to work with remote directories.
Using Graphical FTP Clients
You can use one of the following GUI FTP clients in Linux:
  • gFTP: A graphical FTP client for GNOME at (http://gftp.seul.org)
  • KFTPGrabber: A graphical FTP client for KDE (K Desktop Environment) at www.kftp.org
  • Web browser: A browser such as Firefox, for anonymous FTP downloads
For uploading files, you may want to use gFTP because you typically have to provide a username and password for such transfers. Web browsers work fine for anonymous downloads, which is how you typically download software from the Internet.
All three GUI FTP clients are discussed in the next three sections.
Using gFTP
GNOME comes with gFTP, a graphical FTP client. gFTP isn’t installed by default, but you can download it from http://gftp.seul.org and install it easily. In some distributions, gFTP may be included in a package already, and you just have to install that package.
In Debian, type su - in a terminal window, enter the root password, and then type apt-get install gftp.
In Fedora, log in as root, choose Add/Remove Software from the System Settings menu, and search for gFTP. Choose the package that appears in the search list (gftp-1:2.0.18-7.fc8, as of this writing), click Apply, and the software will be installed.
In Fedora, start gFTP by choosing Applications➪Internet➪gFTP. (If you don’t
see gFTP, log in as root and type yum install gftp, and then look for it in the menu again.) In other distributions, you can find gFTP in the main menu. The gFTP window appears, as shown in Figure 4-1.
The gFTP window just after opening a connection to an FTP serverFigure 4-1: The gFTP window just after opening a connection to an FTP server.
The gFTP window has a menu bar with menus for performing various tasks. Just below the menu bar is a toolbar with a number of buttons and text fields. Here you can type the name or IP address of the remote host, and the username and password needed to log in to the remote host. Figure 4-1 shows the gFTP window after you fill in this information and establish a connection with the remote host by clicking the button with the icon showing two computers (the leftmost one on the toolbar).
To upload or download files with gFTP, follow these steps:
  1. Fill in the hostname or the IP address of the remote system in the Host field.
    If you’ve used that host before, you can select it from the drop-down list that appears when you click the downward-pointing arrow next to the Host field.
  2. Provide the username in the User field and the password in the Pass field, and then click the button with the icon showing two computers (to the left of the Host field).
    This operation causes gFTP to connect to your chosen host and to log in with the username and password you provided. The lower part of the gFTP window shows the FTP protocol messages exchanged between the two systems.
  3. Observe the lower part of the screen for any indication of error messages.
    The directory listing of the remote system appears in the right half of the gFTP window. The left half shows the current local directory.
  4. To upload one or more files from the current system to the remote system, select the files in the list on the left and then click the rightpointing arrow button.
  5. To download files from the remote system, select the filenames in the list on the right and click the left-pointing arrow button.
  6. When you have finished transferring files, choose FTP»Quit.
As these steps show, transferring files with a GUI FTP client, such as gFTP, is simple.
Believe it or not, gFTP isn’t for FTP transfers alone. It can also transfer files using the HTTP (HyperText Transfer Protocol) and secure file transfers using the Secure Shell (SSH) protocol.
Introducing KFTPGrabber
KFTPGrabber is a GUI FTP client for KDE. You find it in the main menu (in the Internet category) on KDE desktops. In Debian, type apt-get install kftpgrabber to install KFTPGrabber (after you type su - to become root).
In Fedora, log in as root, choose System Settings➪Add/Remove Software, and search for KFTPGrabber. Choose the package that appears in the search list (kftpgrabber) and then click Apply. Click Continue at the prompt, and the software will be installed.
When the main KFTPGrabber window appears, it displays your home folder in a view similar to that in Windows Explorer. To connect to an FTP server, choose File➪Quick Connect. A dialog box like the one shown in Figure 4-2 prompts you for the hostname of the FTP server as well as the username and password.
Enter information about the remote FTP server and click OKFigure 4-2: Enter information about the remote FTP server and click OK.
After entering the requested information, click OK. KFTPGrabber establishes a connection to the remote FTP server. In the KFTPGrabber main window, shown in Figure 4-3, you see both the local and remote directories side by side.
FTP transfers become just normal drag-and-drop file copying: Transfer files by simply dragging them from one system’s folder and dropping them on the other system’s folder.
imageFigure 4-3: KFTP Grabber window displays the local directory and the remote FTP server’s directory
When you finish using KFTPGrabber, choose File»Quit.
Using a Web browser as an FTP client
Any Web browser can act as an FTP client, but such programs are best for anonymous FTP downloads, where the Web browser can log in using the anonymous username and any password.
For example, you can use the Firefox Web browser as an FTP client. All you have to know is how to write the URL so that the Web browser can tell that you want to download a file using FTP. The syntax of the FTP URL is
ftp://hostname/pathname
The first part (ftp://) indicates that you want an FTP transfer. The host name part is the name of the FTP server (the name often starts with ftp —for example, ftp.wiley.com). The pathname is the full directory path and filename of the file that you want to download.
If you simply provide the hostname for the FTP server, the Web browser displays the contents of the anonymous FTP directory. If you want to access anonymous FTP on your Linux system, start Firefox (click the Web browser icon on the GNOME panel), type the FTP URL in the Location text box, and press Enter.
Figure 4-4 shows a typical appearance of an FTP directory in Firefox. You can click folders to see their contents and download any files. You can access your local system by using Firefox’s FTP capabilities; for example, type ftp://localhost/pub/ to access the pub directory. (You won’t get a response from your system if you’re not running an FTP server or if you’ve set up your firewall so that no FTP connections are allowed.)
You can use a Web browser to download files from FTP servers Figure 4-4: You can use a Web browser to download files from FTP servers.
In Debian and Fedora, log in as root and type /etc/init.d/vsftpd start (in a terminal window) to start the FTP server. In SUSE, the xinetd super server controls the FTP server vsftpd. The /etc/xinetd.d/ vsftpd configuration file specifies how vsftpd is started. See Book VII, Chapter 1 for more information about xinetd configuration files.
The same approach of accessing anonymous FTP sites works if you type the hostname of some other anonymous FTP server. For example, try typing the following URL:
ftp://ftp.netscape.com/
You get the directory of the ftp.netscape.com server.
Using the Command-Line FTP Client
Knowing how to use FTP from the command line is a good idea. For example, if your GUI desktop isn’t working, you may need to download some files to fix the problem; you can do so if you know how to use the command-line FTP client. The command-line ftp client is available in all Linux distributions and using it is not difficult.
The best way to figure out the command-line FTP client is to try it out. The command is ftp, and you can try out the ftp commands from your Linux system. You don’t even need an Internet connection because you can use the ftp command to connect to your own system.
Note that the output from the ftp command might be different because some distributions, such as Debian, use a text mode version of gFTP as the command-line FTP client.
In the following sample FTP session, the command-line FTP client was used to log in and browse the directories on a Linux system. Here’s the listing illustrating interaction with a typical command-line FTP client:
ftp localhost Connected to localhost.localdomain.
220 (vsFTPd 2.0.3)
Name (localhost:jdoe): (press Enter.)
331 Please specify the password.
Password: (enter the password for the user.)
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> help Commands may be abbreviated. Commands are:
! debug mdir qc send
$ dir mget sendport site
account disconnect mkdir put size
append exit mls pwd status
ascii form mode quit struct
bell get modtime quote system
binary glob mput recv sunique
bye hash newer reget tenex
case help nmap rstatus tick
cd idle nlist rhelp trace
cdup image ntrans rename type
chmod lcd open reset user
close ls prompt restart umask
cr macdef passive rmdir verbose
delete mdelete proxy runique ?
ftp> help mget (to get help on a specific command.)
mget get multiple files
ftp> cd /var (This changes directory to /var.)
250 Directory successfully changed.
ftp> ls (This command lists the contents of the directory.)
227 Entering Passive Mode (127,0,0,1,38,142)
150 Here comes the directory listing.
. . . lines deleted . . .
226 Directory send OK.
ftp> bye (This command ends the session.)
As the listing shows, you can start the command-line FTP client by typing the command ftp hostname, where hostname is the name of the system you want to access. When the FTP client establishes a connection with the FTP server at the remote system, the FTP server prompts you for a username and password. After you supply the information, the FTP client displays the ftp> prompt, and you can begin typing commands to perform specific tasks. If you can’t remember a specific FTP command, type help to view a list of them. You can get additional help for a specific command by typing help command, where command is the command for which you want help.
Many FTP commands are similar to the Linux commands for navigating the file system. For example, cd changes directory, pwd prints the name of the current working directory, and ls lists the contents of the current directory. Two other common commands are get and put: get is what downloads a file from the remote system to your system, and put uploads (sends) a file from your system to the remote host.
Table 4-1 describes some commonly used FTP commands. You don’t have to type the entire FTP command. For a long command, you have to type only the first few characters — enough to identify the command uniquely. For example, to delete a file, you can type dele, and to change the file transfer mode to binary, you can type bin.

Table 4-1
Common FTP Commands
Command
Description
!
Executes a shell command on the local system. For example, !ls lists the contents of the current directory on the local system.
?
Displays a list of commands (same as help).
append
Appends a local file to a remote file.
ascii
Sets the file transfer type to ASCII (or plain text). This command is the default file transfer type.
binary
Sets the file transfer type to binary.
bye
Ends the FTP session with the remote FTP server and quits the FTP client.
cd
Changes the directory on the remote system. For example, cd / pub/Linux changes the remote directory to /pub/Linux.
chmod
Changes the permission settings of a remote file. For example, chmod  644  index.html changes the permission settings of the index.html file on the remote system.
close
Ends the FTP session with the FTP server and returns to the FTP clients prompt.
delete
Deletes a remote file. For example, delete bigimage.jpg deletes that file on the remote system.
dir
Lists the contents of the current directory on the remote system.
disconnect
Ends the FTP session and returns to the FTP clients prompt. (This command is the same as close.)
get
Downloads a remote file. For example, get junk.tar.gz junk.tgz downloads the file junk.tar.gz from the remote system and saves it as the file junk.tgz on the local system.
hash
Turns on or off the hash mark (#) printing that shows the progress of the file transfer. When this feature is turned on, a hash mark prints on-screen for every 1,024 bytes transferred from the remote system. (Its the command-line version of a progress bar.)
help
Displays a list of commands.
image
Same as binary.
lcd
Changes the current directory on the local system. For example, lcd  /var/ftp/pub changes the current local directory to /var/ftp/pub
ls
Lists the contents of the current remote directory.
mdelete
Deletes multiple files on a remote system. For example, mdelete*.jpg deletes all remote files with names ending in .jpg in the current directory.
mdir
Lists multiple remote files and saves the listing in a specified local file. For example, mdir /usr/share/doc/w*  wlist saves the listing in the local file named wlist.
mget
Downloads multiple files. For example, mget *.jpg downloads all files with names ending in .jpg. If the prompt is turned on, the FTP client asks for confirmation before downloading each file.
mkdir
Creates a directory on the remote system. mkdir  images creates a directory named images in the current directory on the remote system.
mls
Same as mdir.
mput
Uploads multiple files. For example, mput *.jpg sends all files with names ending in .jpg to the remote system. If the prompt is turned on, the FTP client asks for confirmation before sending each file.
open
Opens a connection to the FTP server on the specified host. For example, open ftp.netscape.com connects to the FTP server on the host ftp.netscape.com.
prompt
Turns the prompt on or off. When the prompt is on, the FTP client prompts you for confirmation before downloading or uploading each file during a multiple-file transfer.
put
Sends a file to the remote system. For example, put index. html sends the index.html file from the local system to the remote system.
pwd
Displays the full path name of the current directory on the remote system. When you log in as a user, the initial current working directory is your home directory.
quit
Same as bye.
recv
Same as get.
rename
Renames a file on the remote system. For example, rename old.html   new.html renames the file old.html to new. html on the remote system.
rmdir
Deletes a directory on the remote system. For example, rmdir images delete the images directory in the current directory of the remote system.
send
Same as put.
size
Shows the size of a remote file. For example, size bigfile. tar.gz shows the size of that remote file.
status
Shows the current status of the FTP client.
user
Sends new user information to the FTP server. For example, user jdoe sends the username jdoe; the FTP server then prompts for the password for that username.

When downloading files from the Internet, you almost always want to transfer the files in binary mode because the software is usually archived and compressed in a binary form. (Its files aren’t plain text files.) So always use the binary command to set the mode to binary. Then use the get command to download the files.
 
When transferring multiple files with similar names (such as image1.jpg, image2.jpg, and so on), type prompt to turn off prompting. (Otherwise the FTP client will ask you after each file transfer whether you want to transfer the next file.) Then type mget followed by the filename with a wildcard. For example, to download all files with names starting with image and ending with the .jpg extension, type mget image*.jpg.
 
next Linux Administration
Share this article :

0 comments:

Post a Comment

 
Support : Creating Website | Johny Template | Mas Template
Copyright © 2011. Linux - All Rights Reserved
Template Created by Creating Website Published by Mas Template
Proudly powered by Blogger