Linux.com

Feature

CLI magic: File Transfer Protocol

By Joe Barr on July 26, 2004 (8:00:00 AM)

Share    Print    Comments   

Wake up, you goodness-to-GUI slacksters! It's time to get up and get out of that hammock and put your feet on the ground and your hands on the CLI. This week we're going to talk about data in motion. Taking a file from one place on the network. Putting it someplace else. Most often today some form of FTP, the File Transfer Protocol, is used to do those things. It's been part of the Internet since there was an Internet.
If you're interested in FTP history, you might want to read RFC 959. It's a great source of background information. In my opinion, there are few -- if any -- programs in the history of computing that have made a greater contribution to the global spread of free software than FTP.

Old school FTP

If you're an old geek like me, you may very well still use the standard FTP offering included in most Linux distributions. It may not have all the bells and whistles, but it still gets the job done.

To get a file from a distant machine, you need to know either its name or IP address. You may also need to know a valid user ID/password combination. Even public sites often require a signon: user Anonymous and your email address for a password, for example. Let's give it a try. Enter the following at the command line:

ftp ftp.ncftp.com

where ftp.ncftp.com is the name of the site we want to connect to. That results in the following lines appearing in the terminal window:

Connected to ncftpd.com.
220 ncftpd.com NcFTPd Server (licensed copy) ready.
Name (ftp.ncftp.com:warthawg): anonymous
331 Guest login ok, send your complete e-mail address as password.
Password:
230-You are user #1 of 16 simultaneous users allowed.
230-
230 Logged in anonymously.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>

Note that the FTP server we connected to allows "Guest logins," and asks for your email address as a password. Note too, that it identified my system as being a type of Unix and defaulted to binary mode for transfers.

If you don't use binary mode and you download binary data (graphic images, compiled code, compressed data, and the like), you're going to end up with an unusable download that won't be much good for anything.

Let's look around and get the lay of the land on this server. We can use the same ls command with FTP that you know and love from your local command line. Here's what the site had to say when I tried it:

ftp> ls
227 Entering Passive Mode (209,197,102,38,218,14)
150 Data connection accepted from 66.68.177.157:60380; transfer starting.
drwxr-xr-x 3 ftpuser ftpusers 512 Jul 17 1999 gnu
drwxr-xr-x 2 ftpuser ftpusers 512 Jul 20 17:36 libncftp
drwxr-xr-x 3 ftpuser ftpusers 512 Jul 12 01:05 ncftp
drwxr-xr-x 8 ftpuser ftpusers 512 Jul 11 23:41 ncftpd
drwxr-xr-x 3 ftpuser ftpusers 512 Jan 11 2001 unixstuff
drwxr-xr-x 5 ftpuser ftpusers 512 Nov 16 2002 winstuff
226 Listing completed.

I happened to already know that the file I wanted to grab lived in the ncftp subdirectory, so that's where I went:

ftp> cd ncftp
250 "/ncftp" is new cwd.

Now we ask for another directory listing to see what's available:

ftp> ls
227 Entering Passive Mode (209,197,102,38,218,15)
150 Data connection accepted from 66.68.177.157:60636; transfer starting.
drwxr-xr-x 2 ftpuser ftpusers 1024 Jul 12 01:03 binaries
-rw-r--r-- 1 ftpuser ftpusers 95832 Nov 21 1997 ncftp-1.9.5.tar.gz
-rw-r--r-- 1 ftpuser ftpusers 192937 Mar 19 1998 ncftp-2.4.3.tar.gz
-rw-r--r-- 1 ftpuser ftpusers 401561 Jul 10 11:04 ncftp-3.1.8-src.tar.bz2
-rw-r--r-- 1 ftpuser ftpusers 509028 Jul 10 11:04 ncftp-3.1.8-src.tar.gz
-rw-r--r-- 1 ftpuser ftpusers 647750 Jul 10 11:04 ncftp-3.1.8-src.zip
226 Listing completed.

Aha. There it is, the latest NcFTP client. I'll grab the bunzipped version, since it compresses into a smaller tarball than gunzip. Here's how:

ftp> get ncftp-3.1.8-src.tar.bz2

And the FTP server replies:

local: ncftp-3.1.8-src.tar.bz2 remote: ncftp-3.1.8-src.tar.bz2
227 Entering Passive Mode (209,197,102,38,218,18)
150 Data connection accepted from 66.68.177.157:61404; transfer starting for ncftp-3.1.8-src.tar.bz2 (401561 bytes).
100% |***********************| 392 KB 215.70 KB/s 00:00 ETA
226 Transfer completed.
401561 bytes received in 00:01 (215.68 KB/s)

All that's left to do now is to say goodbye by entering the quit command:

ftp> quit
221 Goodbye.
warthawg@linux:~>

Reversing the process -- that is, sending a file from your machine to the distant end -- is a similar exercise. But insteading using the get filename, you say put filename.

If you're wondering why I chose the site I did to demonstrate FTP, it's because I have recently been chastised for using the old, standard-issue FTP client instead of a spiffy client like NcFTP. Now that I've downloaded it, I can check it out to see if it's as much better as claimed.

If you're new to FTP on the command line, I recommend you spend some quality time perusing the output from man ftp. Then when you're down with that, giving NcFTP a whirl. That's what I'm going to do.

Share    Print    Comments   

Comments

on CLI magic: File Transfer Protocol

Note: Comments are owned by the poster. We are not responsible for their content.

Re:sftp

Posted by: Joe Barr on July 27, 2004 12:48 AM
Good suggestions. I have a hunch they will appear someday.<nobr> <wbr></nobr>:)

See ya,
Joe

#

sftp

Posted by: Administrator on July 26, 2004 10:46 PM
Are you going to do an article on sftp and scp also.

#

what is and isn't broken

Posted by: Administrator on July 28, 2004 09:13 AM
First, ftp is a great utility. It's not broken so it's tough for me to even think about trying something new. It was one of the first things I needed when I started using Linux and it's one that I learned almost entirely from the man page. Great little utility. That said, I'll try the newer version you ftp'd in your article just because things do get better in Linux which is something I can't say for the world of Windows.

But what is broken is the way the page displays in Firefox. The text of the article flows off into the grey border just barely. Might want to have someone take a look at that as you folks work on the new design (which looks good to me).

These CLI articles are fantastic. I'm having a good time learning how to better use the real system. It makes me feel empowered. I'm also getting use out of a machine that's too old to really run X.

It's like that quote from Linus. Why use the command line? Because it's fun.

Thanks for the articles. Keep 'em up.

#

This story has been archived. Comments can no longer be posted.



 
Tableless layout Validate XHTML 1.0 Strict Validate CSS Powered by Xaraya