TFM:FTP

From ProgSoc Wiki

Jump to: navigation, search

Contents

FTP: the File Transfer Protocol

Colin Panisset III and Friends[1]

Introduction

FTP is used to transfer files to and from remote network sites. This can mean placing files on a disk in a PC in the next room, or retrieving files from a mainframe in Zambia[2]. A number of sites worldwide accept anonymous FTP (guest logins). This means anybody can "anonymously" obtain publicly-available files from the site. The contents of anonymous FTP archives range from source code and technical reports to meteorological weather maps.[3]

Using FTP

To initiate an FTP session with a remote host, type:

 ftp host-spec

host-spec can be an IP address (eg. 138.25.6.3), a short name (for local sites --- eg. charlie, munnari), or a full name (eg. tsx11.mit.edu).

FTP will attempt to connect to the machine you specified. This is sometimes impossible, due to any number of network problems I won't go into.[4] If FTP can connect, you'll be prompted for a username and password. Log in as you would normally, except the username and password will be your password on the remote machine.

If you don't have an account on the remote machine, you may be able to login anonymously. An anonymous account is not the same as a user account; it only allows browsing and downloading from public directories, and you probably can't upload.

To log in anonymously, type anonymous (ftp and guest may also work) at the "Name:" prompt, and your full e-mail address (your login name followed by "@it.uts.edu.au")[5] at the "Password:" prompt[6].

Connected to ultima.
220 ultima FTP server (SunOS 4.1) ready.
Name (ultima:progsoc): anonymous
331 Guest login ok, send ident as password.
Password: progsoc@it.uts.edu.au
230 Guest login ok, access restrictions apply.
ftp>

Once you've successfully logged in, you can use the following commands:

open host-spec

Opens a connection with the remote host host-spec as if ftp host-spec had been typed on the command-line. Opening another connection will close the current one.

close

Closes your current connection, but does not exit FTP. (But you'll have to open another connection to do anything useful.)

ls

Lists the host's current directory.

dir

Gives a "long list" similar to ls -l.

binary

FTP defaults to ascii (plain text) transmission. To FTP compressed files (.Z, .zip or .tar suffix), executables, images (.gif, .jpg), sound files and other weird binary things[7], you must specify binary transmission. You will probably want to use this - try it if your transfers are failing.

ascii

Toggle to ascii transmission. If you transfer text between machines with different end-of-line conventions (such as Unix and MS-DOS), ASCII transmission automatically converts the file for you. This is nice for text files, but for binary data make sure you use binary mode.

get file

Transfer file from the client to your local host, ie. from "there" to "here". The file will be placed in your current directory (the directory you were "in" when you initiated the FTP session), unless you've changed this with the lcd command.

mget files

To retrieve more than one file, use mget. It can usually handle pattern matching (?, *, etc), although this varies from site to site.

lcd directory

Change local directory: files retrieved are placed in the new current directory; files put will be taken from this directory.

put file

Transfer file from the local host to the remote host, ie. from "here" to "there". You must have write permission, or equivalent, on the remote host's directory.

mput

Put multiple files.

prompt

Toggle between prompt/no prompt mode --- default is on. If prompt is on, FTP will make the user confirm every transfer in an mget or mput.

hash

If requested, FTP will print a hash (#) for every 8K of data transmitted. This can be used to make vague guesses as to transmission speed. Default is off.

quit

Exit FTP.

Not Using FTP

We should mention here, before we go much further, that FTP is part of the quaint set of traditional protocols from back when the internet was made up of just FTP, telnet, email and a few things that went ping just to keep the clocks in sync.[8]

The World Wide Web (HTTP protocol)[9] is more recent and now far more prevalent. Things like FTP have survived in a limited kind of way. (If one of your friends seems to think telnet has survived, please set them straight before they log in again -- "friends don't let friends use telnet").

The point of all this is: all protocols where you send passwords around the place should now have encryption. All other protocols, where you just want to connect somewhere anonymously and grab something, don't need a password so they're OK too. So we have HTTP for clicking on links around the globe, and FTP for publically distributing great slabs of source code from sourceforge.net (for example).

So, what do you do if you really want to send or receive a file to/from an account with a login and password? Well you could turn your entire connection into a point-to-point encrypted tunnel (one of the features of ssh). One of the quicker-and-nastier approaches is scp, "secure copy".

 whophd@niflheim:~$ scp "public_html/*" ckent@rerun.it.uts.edu.au:webbackup

Unfortunately, scp doesn't resemble the behaviour of ftp, because it's based entirely on good old cp -- but here you'll see some of the features of the good old copy command you've probably not used before. Yes, there is an sftp tool, but it doesn't operate like ftp either. (And yes, you can use cp to transfer files across different accounts with passwords in the clear, but if I catch you doing that, I'll take your TFM away).

If you look at the command line above you'll see that there are strictly two arguments, separated by a space. This example has a file being uploaded from a local directory to a remote directory; if you want to download instead, just swap the two arguments around.

The source, of course, needs to have a filename after the (optional) directory -- the only reason there are quotes, is (and this will save you much frustration) because I have used a wildcard (the asterisk will copy all files). Notice that in both cases, the directories have no initial slash and therefore lie under the home directory: The first one because it is the working directory for scp, and the second because it is the default directory for that login.

The standard login@machine:path terminology applies. As long as you don't forget the at-sign, the colon and the quotes when necessary, and don't stick any spaces where they don't belong, then it should work. Remember, you don't need to specify a filename for the destination; any existent directory will do. scp can be a bit tricky to get working the first few times, because it hasn't got any interactivity like FTP. Study the command line and you'll get it.

On PCs, the same people who provided Windows with an ssh client, PuTTY, have provided an scp client. Use pscp.

Example Anonymous FTP Session

This example session logs onto the UTS anonymous FTP server ({\tt ftp.uts</tt>) from charlie. First, ftp.uts is added to the .netrc file in the users home directory. This will automatically log the user in as anonymous and give their e-mail address as the password[10].

 whophd@niflheim:~$ cat >> ~/.netrc
 machine ftp.uts login anonymous passwd cthulhu@it
 ^D
 whophd@niflheim:~$ chmod 600 .netrc

Next, a session is opened to ftp.uts. Commands entered by the user are after the ftp prompt.

 whophd@niflheim:~$ ftp ftp.uts
 Connected to sequoia.ccsd.uts.EDU.AU.
 220 sequoia FTP server (Version 6.23 Wed Feb 24 14:10:37 EST 1993) ready.
 331 Guest login ok, send e-mail address as password.
 230-Welcome to ftp.uts.EDU.AU. at the University of Technology, Sydney.
 230-
 230 Guest login ok, access restrictions apply.
 ftp> cd Mirror
 250-Welcome to the 'Mirror' directory.  All of the files in this
 250-directory are copied from other systems in order to make them
 250-more accessible to users (such as yourself).
 250-
 250 CWD command successful.
 ftp> cd Linux
 250-Welcome to the Linux FTP archive!
 250-
 250-Please read the file README
 250-  it was last modified on Sun Jan 10 20:06:00 1993 - 55 days ago
 250 CWD command successful.
 150 Opening ASCII mode data connection for README (3718 bytes).

The get command allows you to retrieve a file and pipe it into a command. The following retrieves the README file and pipes it through the more command, which will display it one page at a time. (Note: any commands to be carried out locally, such as more in the example below, must be enclosed in double quotes as below.)

 ftp> get README "|more"
 200 PORT command successful.
 local: |more remote: README
 3838 bytes received in 2.5 seconds (1.5 Kbytes/s)
 ftp> cd binaries
 250 CWD command successful.
 ftp> dir
 200 PORT command successful.
 150 Opening ASCII mode data connection for /bin/ls.
 total 10
 -r--r--r--  1 root     wheel           0 Aug  8  1992 .notar
 drwxr-xr-x  2 root     wheel         512 Jan 21  1991 compilers
 drwxr-xr-x  2 root     wheel         512 Jan 21  1991 lib
 drwxr-xr-x  2 root     wheel         512 Mar  1 13:19 usr.games
 226 Transfer complete.
 636 bytes received in 0.72 seconds (0.86 Kbytes/s)
 ftp> cd usr.games
 250 CWD command successful.
 ftp> dir
 200 PORT command successful.
 150 Opening ASCII mode data connection for /bin/ls.
 total 3981
 -r--r--r--  1 root     wheel      251437 May  7  1992 dungeon.tar.Z
 lrwxrwxrwx  1 root     1              34 Mar  1 13:19 rain.tar.Z
 -r--r--r--  1 root     wheel      444077 Apr 28  1992 rayshade406.tar.Z
 -r--r--r--  1 root     wheel       66551 Jun  3  1992 tetris-bin.tar.Z
 -r--r--r--  1 root     wheel      302325 Jul 25  1992 xgames.tar.Z
 -r--r--r--  1 root     wheel     1235607 Oct 30 01:57 xtank1.3f.tar.Z
 226 Transfer complete.
 1308 bytes received in 0.3 seconds (4.3 Kbytes/s)

The file xtank1.3f.tar.Z should be a compressed tar archive of the binaries for the xtank game (for the Linux operating system). Since it is compressed (and it contains binary data anyway) transfer mode is set to binary mode with the bin command before transferring the file.

Further Information - ncftp is good

If you regularly FTP to a particular machine from the Faculty network, you might want to create a .netrc entry to automate the logon procedure. The manual page for netrc(4) has more information on how to do this. Also look at the X front end to ftp --- ftptool. There's a newer, better FTP out there now --- ncftp. It has the unquestionably good quality of being able to start receiving a file from the packet you had got up to if a previous FTP session was interrupted. Again, look at the man page.


  1. "Let's call it cooperation!"
    "No! Let's call it George!"
    (This is a Sesame St joke. You may be too young to understand.)
  2. Or Both, for any Zambians who've somehow gotten a copy of this manual and were wondering how they were going to get their assignments off their system to a PC disk to take home and finish tonight. Hi guys.
  3. A slight stir was caused in the 1990s when it was found that the majority of the megabytes being transferred across the networks were actually digitised images of a rather saucy nature MP3 files... of course, nowadays, you simply wouldn't find that happening on a protocol whose source of distribution is centralised (but we'll leave peer-to-peer file sharing for another chapter).
  4. They're too complex, and you probably can't do anything about them. Try again later.
  5. or your ProgSoc address. Or any email address, really.
  6. With the Faculty system, just typing `yourlogin@' should suffice.
  7. Like MS Word .doc files
  8. There are in fact protocols that go `ping', and others that keep clocks in sync, but they are entirely different things.
  9. Technically, I should say HTT protocol, but that just looks bad
  10. See the chapter on Electronic Mail.
Personal tools