The DARPA Commands, Including ftp and telnet


Unlike the r* commands, the DARPA commands can be used for networking between UNIX computers and machines running other operating systems.

Using ftp

Copying files to and from remote machines is one of the most common networking tasks. As you have seen, you can use rcp to copy files to and from a remote machine when this machine is also running a version of the UNIX System that includes rcp and you have a login on the remote machine or the machines trust each other. However, you may want to copy files on machines running other operating systems, or variants of the UNIX System that do not support rcp. This can be done using the ftp command (as long as the remote machine supports the ftp daemon ftpd). You also can use ftp to copy files when you do not know the names of the files.

The ftp command implements the File Transfer Protocol (FTP), permitting you to carry on sessions with remote machines. When you issue an ftp command, you begin an interactive session with the ftp program, like this:

 $ ftp ftp>

You can display a list of available ftp commands by entering a question mark, ?, or typing help at the ftp prompt. You can get information on a command using the help command. For instance, you can get information on the open command using this ftp command line:

 ftp> help open

To run an ftp command, you only need to supply ftp with as many letters of the command name as are needed to uniquely identify the command. If you do not supply enough letters to uniquely identify the command, ftp tells you,

 f tp>n ?Ambiguous command ftp>

Opening an ftp Session

To begin a session with a remote host, you use the ftp open command. The following is an example of the beginning of an ftp session with the remote host jersey:

 ftp> open (to) jersey Connected to jersey 220 jersey FTP server (Version 1.1 May 16 2006) ready.   Name (jersey:khr): khr 331 password required for khr. Password: a2ux4     {this is not displayed} 230 user khr logged in.

The first line shows that the ftp command open was issued. Then, ftp came back with the prompt "(to)" and the name of the remote machine, jersey, was supplied as input. The third and fourth lines are the response from the FTP server on the remote machine. The fifth line is the prompt for the login name on the remote machine. The sixth line is the statement from the FTP server that the user khr needs to supply a password. Then the password prompt is given. After the correct password has been supplied (which is not echoed back), the FTP server gives the message that khr is logged in.

You can also specify a remote host when you issue your ftp command line. For instance, to begin an ftp session with the remote host jersey, enter the command

 $ ftp jersey

Using ftp Commands

Once you have opened an ftp session with a remote host, you can use the many different ftp commands to perform a variety of tasks on the remote host. For instance, you can list all the files accessible to you on the remote host by issuing an ftp ls command. You can also change directories using an ftp cd command, but you will not be able to access files in this directory unless you have permission to do so. When you use ftp commands, you are not running commands on the remote machine directly; instead, you are giving instructions to the ftp daemon on the remote machine.

You can escape to the shell and run a shell command on your local machine using an exclamation mark followed by the command. For instance, you can run the date command with this ftp command line:

 ftp> ! date

Copying Files Using ftp

To copy a file once you have established your ftp connection, use the get and put commands. Before copying a file, you should make sure the correct file transfer type is set. The default file transfer type is ASCII (although on some systems the system administrator will set up a binary default). To set the file transfer type to binary, use this command:

 ftp> binary

To set the file transfer type back to ASCII, use this command:

 ftp > ascii

Once the file transfer type is set, you can use the get and put commands. For instance, to copy the file lists from the remote host jersey, with which you have established an ftp session to your machine, use the get command of ftp, as the following session shows:

 ftp> get lists 200 PORT command successful. 150 ASCII data connection for names (192.11.105.32, 1550) (35 bytes). 226 ASCII Transfer complete. local: lists remote: lists 43 bytes received in 0.02 seconds (2.1 Kbytes/s)

To copy the file numbers from your machine to jersey, use the put command of ftp, as the following session shows:

 ftp> put numbers 200 PORT command successful. 150 ASCII data connection for numbers (192.11.105.32, 1552). 226 Transfer complete. local: numbers remote: numbers 6355 bytes sent in 0.22 seconds (28 Kbytes/s)

When you use either the get or put command, ftp reports that the transfer has begun. It also reports when completion occurs and tells you how long the transfer took.

You can copy more than one file using the mget and mput commands, together with the appropriate metacharacters. (These metacharacters are interpreted by ftp as you would expect; there are no problems with having local shells interpret metacharacters as with r* commands because ftp is an application program rather than a shell.) When you use either of these commands, ftp asks interactively whether you wish to transfer each file. You enter y if you want to transfer the file and n if you do not want to transfer the file. After going through all files, you get an ftp prompt.

For example, to copy the remote files t1 and t2, but not t3, you can use the following session:

 ftp> mget (remote-files) t* mget t1? y 200 PORT command successful. 150 ASCII data connection for t1 (192.11.105.32, 2214) (180 bytes). 226 ASCII Transfer complete. local: t1 remote: t1 190 bytes received in 0.02 seconds (9.3 Kbytes/s) mget t2? y 200 PORT command successful. 150 ASCII data connection for t2 (192.11.105.32, 2216) (1258 bytes). 226 ASCII Transfer complete. local: t2 remote: t2 1277 bytes received in 0.04 seconds (31 Kbytes/s) mget t3? n ftp>

Similarly, to copy the files names and numbers, but not lists (if these are all the files in the current directory on the local machine) to the remote machine, you can use this session:

 ftp> mput (local-files) * mput lists? n mput names? y 200 PORT command successful. 150 ASCII data connection for names (192.11.105.32, 2220). 226 Transfer complete. local: names remote: names mput numbers? y 200 PORT command successful. 150 ASCII data connection for numbers (192.11.105.32,2222). 226 Transfer complete. local: numbers remote: numbers 43 bytes sent in 0.11 seconds (0.38 Kbytes/s). ftp>

Terminating and Aborting ftp Sessions

To terminate an ftp session, type quit at the ftp prompt:

 ftp> quit 221 Goodbye.

If the remote machine or the communications link goes down, you can use the BREAK key (interrupt) to abort the ftp session and return to your shell on the local machine.

Retrieving Files via Anonymous FTP

A tremendous variety of public domain software is available on the Internet. The most common way that these programs are distributed is via anonymous FTP, a use of ftp where users do not need a login on the remote machine. You can find sources for many public domain programs that you can obtain using anonymous FTP by reading netnews or by consulting various web sites.

It would be infeasible to add an entry to the password database of a machine whenever a remote user on the Internet logs in. To avoid this problem, administrators can configure their systems so that remote users can use ftp to log in, for the purpose of copying a file, with a particular string such as “anonymous” or “ftp”; a valid e-mail address or any string is accepted as a valid password. Usually systems ask users to supply “ident” or “guest” as their password; the system expects the remote user to enter a name or electronic address as the password.

The following example illustrates an anonymous FTP session:

 $ ftp jersey.att.com Connected to jersey.att.com 220 jersey.ATT.COM FTP server ready. Name (jersey.att.com: khr): anonymous 331 Guest login ok, send ident as password. Password: khr@orono. maine.edu {not displayed} 230 Guest login ok, access restrictions apply. ftp> cd /pub/math 250 CWD command successful. ftp> get primetest 200 PORT command successful. 150 ASCII data connection for primetest (192.11.105.32, 2229) (17180 bytes). 226 Transfer complete local: primetest remote: primetest 17180 bytes received in 19 seconds (0.90 Kbytes/s) ftp> quit 221 Goodbye

Large files and software packages are often made available in compressed tar format, which have a .tar.Z extension. To use ftp to transfer such files, you must first use the ftp binary command. When you receive the file from the remote system, first use uncompress and then tar to recover the original file.

Chapter 17 explains how you can enable your system to share files via anonymous FTP.

The use of ftp for anonymous file transfer on the Internet is far and away the predominant use of ftp. There is a reservoir of archive sites that hold thousands of files. Table 9–1 displays a list of some commonly used ftp commands and their actions.

Table 9–1: The Most Commonly Used ftp Commands

Symbol

Meaning

Example

Effect

!

Specify which part of command to substitute

!cat

Redo last cat command

!!

Redo previous command

!!>file

Redo last command and send output to file

!n

Substitute event n from history list

!3

Go to the third command

!-n

Substitute nth preceding event

!3

Go back three commands

!cmd

Substitute last command beginning with cmd

!fiie>temp

Redo last find command and send output to temp

:

Introduce argument specifiers

date>!:3

Run date and send output to third file from last command

*

Substitute all arguments

cat !ls:*

cat files listed as arguments to last Is command

$

Substitute last argument

mv !:$ newdir

mv last file from previous command to newdir

n

Substitute nth argument

rm !:4 !:6

rm fourth and sixth files named in last command

s/abc/def/

Switch abc to def

!cat:s/kron/korn/

Redo last cat command, changing kron to korn

^abc^def

Run last command and change abc to def

^oldfile^old_file

Redo previous command, changing oldfile to old_file

Invoking ftp via a Web Browser

You do not need to use the traditional command-line interface for ftp if you have a web browser such as Firefox or Mozilla installed on your system. When you have a web browser, you can access an anonymous FTP site by using a URL of the form ftp://ftp.foobar.com (where ftp://ftp.foobar.com is the anonymous FTP site you wish to access). See Chapter 10 for details.

Using tftp

Another command is available that can be used for file transfer to and from remote hosts. The tftp command, which implements the Trivial File Transfer Protocol (TFTP), uses the User Datagram Protocol (UDP) instead of the Transmission Control Protocol (TCP) used by ftp. You can use tftp when you have no login on the remote machine. Because there is no validation of users with tftp, it can only be used to transfer files that are publicly readable. Because tftp does not authenticate users, it is extremely insecure. This means that it is often unavailable on server machines.

Unlike ftp, when you use tftp you are not running an interactive session with a remote host. Instead, your system communicates with the remote system whenever it has to.

You begin a tftp session by issuing this tftp command:

 $ tftp tftp>

Once the tftp session has been started, you can issue a tftp command. You can display a list of tftp commands by entering a question mark (?) at the tftp prompt:

 tftp> ? Commands may be abbreviated. Commands are: connect  connect to remote tftp mode     set file transfer mode put      send file get      receive file quit     exit tftp verbose  toggle verbose mode trace    toggle packet tracing status   show current status binary   set mode to octet ascii    set mode to netascii rexmt    set per-packet retransmission timeout timeout  set total retransmission timeout ? print  help information

For instance, to connect to a remote host for copying files, you use this tftp connect command:

 $ tftp tftp> connect (to) jersey

After you enter the tftp command connect, tftp gives you the prompt “(to).” You enter the system name jersey Then tftp establishes a connection to the machine jersey (if it can).

You can also establish a tftp session by supplying the name of the system on your command line, like this:

 $ tftp jersey

You can use the tftp status command to determine the current status of your tftp connection:

 tftp> status connected to jersey mode: netascii verbose: off tracking: off remxt-interval: 5 seconds max-timeout: 25 seconds

Remote Login Using telnet

You can use rlogin to log in to a remote UNIX computer. However, you may want to log in to a system running some other operating system, or a different version of the UNIX System. This can be accomplished using the telnet command.

To begin a telnet session, you run the telnet command, like this:

 $ telnet telnet>

Once you have established a telnet session, you can run other telnet commands. You can display a list of these commands by entering the telnet command help or a question mark:

 telnet> help Commands may be abbreviated. Commands are: close   Close current connection display display operating parameters mode    try to enter line-by-line or character-at-a-time mode open    connect to a site quit    exit telnet send    transmit special characters ('send ?' for more) set     set operating parameters ( 'set ?' for more) status  print status information toggle  toggle operating parameters ('toggle ?' for more) z       suspend telnet ?       print help information

You can use the telnet open command to establish a telnet session with a remote host. For instance, you would use this command line to start a session with the remote machine michigan:

 telnet> open michigan

You can also establish a telnet session with a remote host by supplying the machine name as an argument to the telnet command. For instance, you can start a session with michigan by typing this:

 $ telnet michigan

This is the response:

 Trying ... Connected to michigan Escape character is '^]'

It is followed by the ordinary login sequence on the machine michigan. Of course, you must have credentials to log in to michigan. Also note that telnet tells you the escape character it recognizes, which in this case is CTRL-].

If you try to use telnet to log in to a machine that is not part of your network, telnet searches through the host database on your machine. Then it tells you that the machine you are trying to log in to is not part of the network. After receiving this message, you receive another telnet prompt. If you wish, you can terminate your telnet session by typing quit, or simply q.

Aborting and Suspending telnet Connections

You can abort a telnet connection by entering the telnet escape character, which usually is CTRL-], followed by quit. This returns you to your local machine. When you abort a connection to a machine you reached with a series of telnet commands, you return to your original machine.

You can suspend a telnet connection by typing CTRL-Z. When you do this, the telnet process becomes a background process. To reactivate a suspended telnet session, type fg.

Invoking telnet via a Web Browser

If a web browser such as Netscape Navigator is installed on your system, you can set up a telnet session by supplying a URL in the form telnet://foobar.com (where foobar.com is the name of the remote system you wish to log in to). See Chapter 10 for details.

Obtaining Information About Users and Hosts

Before using remote commands, you may want to obtain some information about machines and users on the network. You can get such information using any of several commands provided for this purpose, including rwho, which tells you who is logged in to machines on the network; finger, which provides information about specific users on a local or remote host on your network; ruptime, which tells you the status of the machines on the network; and ping, which tells you whether a machine is up or down. You may also want to run traceroute to investigate network issues; this command will tell you the route packets are taking to reach a remote host.

The rwho Command

You can use the rwho command to print information about each user on a machine on your network. The information you get includes the login name, the name of the host, where the user is, and the login time for each user. For instance,

 $ rwho avi    peg:console    Oct 15 14:53 khr    pikes:console  Oct 15 17:32 jmf    arch:ttya2     Oct 15 12:21 rrr    homx:ttya3     Oct 15 17:06 zeke   xate:ttya0     Oct 15 17:06

The finger Command

You can obtain information about a particular user on any machine in your network using the finger command. You obtain the same type of information about a user on a remote machine as you would for a user on your own machine (see Chapter 2). To obtain information about a user on a remote host, supply the user’s address. For instance, to obtain information about the user khr on the machine jersey, use this command line:

 $ finger khrjersey

On some machines, finger is disabled for remote users for security reasons.

The ruptime Command

You can use the ruptime command to obtain information about the status of all machines on the network. The command prints a table containing the name of the host on the local network, whether the host is up or down, the amount of time it has been up or down, the number of users on that host, and information on the average load on that machine for the past minute, 5 minutes, and 15 minutes. For example,

 $ ruptime aardvark   up 21+02 24,  6 users,   load   0.09,  0.05,  0.02 bosky      up 20+07 58,  5 users,   load   1.23,  2.08,  1.87 fickle     up  6+18 48,  0 users,   load   0.00,  0.00,  0.00 jazzy      up  1+02 31,  8 users,   load   4.29,  4.07,  3.80 kitsch     up 21+02 06,  9 users,   load   1.06,  1.03,  1.00 lucky      up 21+02 06,  4 users,   load   1.09,  1.04,  1.00 olympia    up 21+02 05,  0 users,   load   1.00,  1.00,  1.00 sick     down  2+07 14 xate       up  2+06 39,  1 user,    load   1.09,  1.20,  1.57

The preceding shows that the machine aardvark has been up for 21 days, 2 hours, and 24 minutes, has 6 current users logged in, had an average load of 0.09 processes in the last minute, 0.05 processes in the last 5 minutes, and 0.02 processes in the last 15 minutes. The machine sick has been down for 2 days, 7 hours, and 14 minutes.

The ping Command

Before using a remote command, you may wish to determine whether the remote machine you wish to contact is up. You can do this with the ping command. Issuing this command with the name of the remote machine as an argument determines whether a remote host is up and connected to the network or whether it is down or disconnected from the network.

For instance, the command

 $ ping jersey jersey is alive

tells you that the remote host jersey is up and connected to your network. If jersey is down or is disconnected from the network, you would get this:

 $ ping jersey no answer from jersey

A remote system may be running and connected to your network, but communication with that system may be slow. You can obtain more information about the connection between your system and the remote system if you are running a variant of UNIX that supports options to the ping command (or that supports the traceroute command-see the next section). For example, you may be able to monitor the response time between your system and the remote system (on Solaris, the -s option to ping does this). You may even be able to use the ping command to track the actual route that packets between your system and the remote system take in the Internet (on Solaris the -svlR combination of options does this). Consult the manual page for ping on your particular system for details on how to obtain similar information for Internet connections from your system.

The traceroute Command

The traceroute command is available on most modern UNIX variants. This command can be used to find the route through the Internet packets from your computer taken to reach a remote host. You may want to use this command when you get no response from a remote host when you use the ping command. Running the traceroute command will tell you whether there is a problem with your connection to the Internet or whether packets are just not reaching their ultimate destination. That is, you will be able to see whether there is a broken link that is preventing your packets from the remote host, or whether a particular link is slow.

The information shown in each line of traceroute output includes

  • The hop number. Hop 1 begins at your machine; all hops needed to reach the destination are displayed, if this host can be reached, as long as the number of hops does not exceed a preset limit (which is 30 hops by default, but which can be changed using the -m option to traceroute). If the destination cannot be reached, all hops that make their way to an intermediate machine are shown.

  • The host name at each hop, or the IP address when there is no reverse DNS for this host.

  • The IP address, shown in parentheses.

  • The times used by three separate probes to reach the host at this hop.

For example, here is the output of the traceroute command when run from the machine www.net.berkeley.edu with the machine stanford.edu as the destination.

 $ traceroute stanford.edu 1  inr-211-inr-203--128–32–206–1.HSRP.Berkeley.EDU (128.32.206.1) 0.433 ms 0.349 ms 0.306 ms 2  g3–1.inr-201-eva.Berkeley.EDU (128.32.255.1) 0.544 ms 0.389 ms 0.369 ms 3  ge-1–2-0.inr-002-reccev.Berkeley.EDU (128.32.0.36) 49.401 ms 0.445 ms 10.171 ms 4  hpr-oak-hpr-ucb-ge.cenic.net (137.164.27.129) 0.797 ms 0.616 ms 0.760 ms 5  hpr-stan-ge-oak-hpr.cenic.net (137.164.27.158) 1.947 ms 1.943 ms 1.962 ms 6  bbr2-rtr.Stanford.EDU (171.64.1.133) 2.165 ms 2.261 ms 2.261 ms 7  www4.Stanford.EDU (171.67.20.36) 2.248 ms 2.360 ms 2.384 ms




UNIX. The Complete Reference
UNIX: The Complete Reference, Second Edition (Complete Reference Series)
ISBN: 0072263369
EAN: 2147483647
Year: 2006
Pages: 316

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