By Heike Jurzik
FTP (File Transfer Protocol) is a suite of Internet protocols that helps users transfer data between two computers. One computer serves as the FTP client, and the other machine is the server.
Most FTP servers provide anonymous services, in which you can enter anonymous or ftp as your login name and not provide a password, although it is considered a friendly gesture to enter your own email address. Other servers, run by webspace providers, for example, prompt you to enter your username and your password for the purpose of authentication.
Be aware that, in contrast to secure protocols (such as Secure Shell SSH), a protocol such as FTP transmits usernames, passwords, and other data across the network in clear text, and FTP is thus unsuitable for exchanging confidential information.
If you prefer the simplicity of the command line and would rather not use your web browser's or file manager's internal FTP client, then you should check out the two command-line alternatives, FTP and NcFTP.
To change directory on the local machine, use the lcd command. For other local commands, start the command with an exclamation mark, for example, !ls outputs the local directory listing.
FTP is a simple command-line client that any Linux distribution will include by default. To open a connection, do the following:
Alternatively, you can launch the client first by typing ftp, and then you'll enter the following command at the ftp command prompt:
ftp> open ftp.server.com
to connect to the required target. After establishing a connection, you will be prompted to log in. As mentioned earlier, you can then either type anonymous, ftp, or a username provided by the webspace provider, along with the matching password (Listing 1). Typing the password can be quite tricky - in contrast to NcFTP, FTP does not display an asterisk for each character you type.
|Listing 1: Connecting with FTP|
01 ftp> open ftp.debian.org 02 Connected to ftp.debian.org. 03 220 saens.debian.org FTP server (vsftpd) 04 Name (ftp.debian.org:huhn): ftp 05 331 Please specify the password. 06 07 Password:
After logging in, FTP displays the ftp> prompt, and you can start to enter commands. The help or ? commands output an overview of the available commands (Figure 1).
Many of the commands use a similar syntax to Bash commands (for example, cd, ls, exit, etc.). Some of the commands are self-explanatory, and others are fairly cryptic. You can ask the program for more help on individual commands such as this:
ftp> help command
To discover the current directory server-side, enter pwd ("print working directory") like in Bash, and typing the familiar ls command will give you a directory listing. cd directory takes you to another directory, cd .. climbs up one level in the directory tree, and cd takes you to the root directory on the FTP server.
get and mget help you download data from the FTP server to the current directory on your local machine. While get expects you to enter the complete filename, mget also supports wildcards. To shovel all the files in a specific directory onto your local machine, type mget * at the prompt.
Of course, you can be more precise if you like:
ftp> mget *.tar.gz
will download files with the .tar.gz extension. By default, FTP will prompt you to confirm downloading every single file that matches the pattern. You can type y or n to either launch the transfer or skip a file, respectively.
The prompt command helps you avoid these questions:
ftp> prompt Interactive mode off.
This also applies to the mput command, which uploads data to the server, and to mdelete, which deletes data server side - both assume you have privileged (write) access to the FTP server.
The close command shuts down the connection, and the quit command closes the session and quits the program.
Although most distributions do not include the NcFTP command-line client by default, the client is usually on the installation media, or download the tool from the NcFTP homepage , which has versions for various platforms.
Basic operations are not vastly different from FTP; to open a connection, you can either specify a target upon launching the program, or enter the open command at the prompt (Listing 2).
|Listing 2: Opening a connection|
01 huhn@asteroid:~$ ncftp 02 Ncftp 3.1.8 (Jul 27, 2004) by Mike Gleason (http://www.Ncftp.com/contact/). 03 ncftp> open ftp.debian.org 04 Connecting to 184.108.40.206... 05 saens.debian.org FTP server (vsftpd)Logging in...
NcFTP automatically handles logging on to anonymous servers; if you need to enter a username and password, provide the details when you run the command:
ncftp> open -u username -p password ftp.server.com
The help, pwd, cd, lcd, close, and quit commands work just like in FTP, and thus it comes as no surprise that the command for listing directories is titled ls. However, NcFTP has an additional feature here; assuming the server supports this, ls -l will give you an extended listing, similar to ls -la, which will display hidden files and directories.
NcFTP has more to offer - the client supports tab completion, which you will be familiar with from Bash. You can type the first couple letters of a command, or a file/directory name, and press [Tab]. NcFTP will complete the name if it is unique. Typing the first two letters of a command and pressing the tabulator key tells NcFTP to output all the commands that start with this letter.
As you probably expected, the command for downloading files to your local mac is titled get. NcFTP adds a convenient feature that shows the download progress and transfer rate at the bottom of the screen (Figure 2).
NcFTP has another practical feature - the ability to restart cancelled downloads. When you run get against a file that already exists on your local machine, NcFTP prompts you that The local file filename already exists.
The FTP client then outputs the file size and timestamp, details for the local and (assuming the files are different) remote files.
The program then asks you what to do next. As you can see from Figure 3, users have a number of options at this point:
Just like the ls, get has a number of options with additional features. To transfer a whole folder recursively (that is, including all of its files and subdirectories), do this:
ncftp> get -R directory
Additionally, get has a parameter that lets users store a file under a different name. The following command:
ncftp> get -z README README.TXT
will store the README file as README.TXT locally.
Also, get has another very practical feature, especially for text files: by default, NcFTP will use binary transfer mode (meaning, it will not change the file content when transferring files). If the file is an ASCII file with different end of line characters for editors on different platforms, the following command:
ncftp> get -a file.txt
will tell NcFTP to download the file in ASCII mode. To change to ASCII mode permanently, run the type command:
ncftp> type ascii ncftp> type Type is A (ASCII). ncftp> type binary ncftp> type Type is I (binary/image).
As you can see, type not only toggles modes, but shows you the current mode.
Finally, the get command has a -f parameter that tells the client to overwrite existing files, without prompting you to append, restart the download, or anything like that.
Some NcFTP commands automatically run client actions as background processes. Using the bgget, bgput, and bgstart commands gives you the advantage of immediately freeing the FTP client prompt for more input.
You first must tell the program the transfer direction and the source data by running the bgget or bgput command (Listing 3). Again, running the (bg)put command assumes write privileges on the server.
|Listing 3: bgget|
01 ncftp ...e/pool/main/m/man2html > bgget *.deb 02 + Spooled: get man2html_1.5-23.1_alpha.deb 03 + Spooled: get man2html_1.5-23.1_arm.deb 04 + Spooled: get man2html_1.5-23.1_i386.deb 05 + Spooled: get man2html_1.5-23.1_m68k.deb 06 + Spooled: get man2html_1.5-23.1_powerpc.deb 07 + Spooled: get man2html_1.5-23.1_sparc.deb
The jobs command displays the transfer jobs waiting in the spooler. You can start transferring by entering bgstart. NcFTP will then process the jobs in the background (even after you quit the program), and store the results in a logfile:
Watch the "/home/huhn/.ncftp/spo ol/log" file to seehow it is pr ogressing.
tail -f is a very useful way of monitoring the logfile, because it will update the display whenever the file changes.
This lets you monitor NcFTP's progress without needing to run the less or more pagers multiple times.
To avoid typing, or to jog your memory, you can use bookmarks in NcFTP. To do so, type bookmark during a session, and press [Enter] to confirm the name suggested by NcFTP, or enter your choice of name for the bookmark:
ncftp> bookmark Enter a name for this bookmark,or hit enterfor "debian": debiantest Bookmark "debiantest" saved.
The NcFTP client also lets you store a bookmark when you type close or quit. In fact, NcFTP will even support password-protected accounts, storing your (encrypted) credentials below your home directory in .ncftp/bookmarks.
The next time you open the same connection, just type open and pass in the bookmark name. Alternatively, type open and press [Enter] to display a list of bookmarks. Incidentally, the bookmarks command will also output an overview.
In this view, the FTP client even gives you a simple editor that you can use to edit your bookmarks:
When you are done editing your bookmarks, you can press [X] to quit the bookmark editor.
 NcFTP website: http://www.ncftp.com
Heike Jurzik studied German, Computer Science and English at the University of Cologne, Germany. She discovered Linux in 1996 and has been fascinated with the scope of the Linux command line ever since. In her leisure time, you might find Heike hanging out at Irish folk sessions or visiting Ireland.