(Message inbox:1390)
Return-Path: billb@JASON
Received: by JASON (5.45/4.7)
	id AA13396; Fri, 2 May 86 16:15:07 EDT
Received: by ATHENA (5.45/4.7)
	id AA08166; Fri, 2 May 86 16:14:52 EDT
Received: by JASON (5.45/4.7)
	id AA13385; Fri, 2 May 86 16:14:37 EDT
Message-Id: <8605022014.AA13385@JASON>
To: lbm@JASON
Subject: Yet again . . .
Date: Fri, 02 May 86 16:14:31 -0500
From: Bill Bryant <billb@JASON>

@chapter[File Transfer and File Backup]

Athena cannot backup the files you keep on a
workstation's hard disk.
That is your responsibility.
If you insist on leaving important files on the workstation
without adequate backup,
and the hard disk suffers a head crash,
say good bye to all your work.

Note as well that space on the hard disk is relatively small.
This won't be a problem in the future,
when Athena makes private RVD lockers available for
public consumption,
but for now,
you probably won't have room to keep all your timesharing files
in your workstation account.
This is especially true for those of you
who share workstations with other developers.
To solve both the backup problem and the space problem,
consider employing the following procedure in your day to day
use of the workstation:
@begin[enumerate]
When you login to your workstation,
create a seperate window,
and login to your timesharing account.

Transfer your work files from the timesharing account
to your workstation account.

Work with your files on the workstation.

When you finish your work,
transfer the files back to timesharing account,
and delete the workstation copies
so that other users have room on the hard disk to do their work.
@end[enumerate]

@section[File Transfer Utilities]

The utilities you are most likely to use are @i[rcp] and
@i[ftp].
Because it lets you transfer whole Unix subtrees,
@i[rcp] is the utility you should use to backup your
workstation files.
Note that @i[rcp] won't let you transfer files
unless the remote machine trusts your local machine.
Unfortunately,
setting up trust between machines can lead to holes in security,
so you will probably want to
use @i[rcp] on machines that you access regularly.

The @i[ftp] utility gets around the machine trust problem by making
login to the remote machine before letting you
transfer files.
The program lets you transfer single files and multiple files,
but unlike @i[rcp], @i[ftp] cannot transfer entire Unix subtrees.
If you want to use @i[ftp] to transfer multiple files,
the files must be grouped together in the same directory.

@section[Using rcp]

First make sure that the @i[.rhosts] file in your workstation account
gives the timesharing machine permission to initiate @i[rcp] transfers.
The file should list the timesharing machine's name in this format:
@begin[example]
HERA.MIT.EDU
@end[example]
All @i[rcp] file transfers should be run from timesharing machines.
You can't run @i[rcp] from the workstation unless the workstation's
hostname is in a timesharing system's @i[.rhost] file,
and that is a big security hole.
Avoid putting workstation names in timesharing @i[.rhost] files.

@section[Transferring Directory Trees with rcp]

To transfer directory trees from timesharing
accounts to workstation accounts,
use @i[rcp] as follows:
@begin[example]
host% @b[rcp -r @p(local-dir) @p(workstation:remote-dir)]
@end[example]
where @i[local-dir] is the timesharing directory,
@i[workstation] is the workstation's hostname,
and @i[remote-dir] is the workstation directory.
For instance,
suppose I have a timesharing directory @i[/mit/b/i/billb/programs]
that I want to transfer to my workstation @i[E40-342A-1].
This is what I type:
@begin[example]
host%@b[rcp -r /mit/b/i/billb/programs E40-342A-1:/mit/billb/programs]
@end[example]

If I wanted to backup the workstation @i[programs] 
directory on the timesharing system,
say in a directory called @i[Workback/Currback]
I would type this:
@begin[example]
host% @b[rcp -r E40-342A-1:/mit/billb/programs /mit/b/i/billb/Workback/Currback]
@end[example]

@section[Transferring Single Files with @i(rcp)]

You can also use @i[rcp] to transfer single files.
Just drop the @i[-r] option when you use the command.

@section[Using ftp]

If you need to transfer files between machines that don't trust each other,
@i[ftp] is the logical choice.
The general @i[ftp] procedure works like this:
@begin[enumerate]
Login to your workstation and move to the directory
you want to transfer files to or copy files from.
(If you want to transfer files to or from your
home directory on the local machine, you do not
have to change directories.)

Start @i[ftp] and login to the remote machine.

Use @i[ftp]'s @i[cd] command to change the remote machine's current directory
to the one you want to copy files from or transfer files to.
(If you want to transfer files to or from your home directory
on the remote machine, you do not have to change directories.)

Use @i[ftp]'s file transfer commands to transfer your files.

Exit @i[ftp].
@end[enumerate]

@section[Starting and Exiting ftp]

To start @i[ftp], type:
@begin[example]
host% @b[ftp @p(machinename)]
@end[example]
where @i[machinename] is the name of the machine you want
to transfer files with.
The utility connects you to the other machine and asks you
to login to an account there.
You must enter the account's username and password before
@i[ftp] will let you transfer files. 
You can login to any account on the remote machine if you know
the account's password.

Suppose I want to use @i[ftp] to transfer files between my
workstation @i[cassandra] and the timesharing machine @i[odysseus].
This is what I do:
@begin[example]
cassandra% @b[ftp odysseus]
Connected to ODYSSEUS.MIT.EDU.
220 odysseus FTP server (Version 4.103 Fri Dec 6 07:57:26 EST 1985) ready.
Name (ODYSSEUS.MIT.EDU:):@b[ billb]	  @b[<--- I enter my username.]
Password (ODYSSEUS.MIT.EDU:billb):	  @b[<--- I enter my password.]
331 Password required for billb.	  @b[<--- @i(ftp) displays meaningless message.]
230 User billb logged in.	          @b[<--- @i(ftp) logs me in.]
ftp>					  @b[<--- @i(ftp) displays its command prompt.]
@end[example]

@section[If You Make a Mistake While Trying to Login . . .]

If you make a typing mistake when trying to login,
@i[ftp] reacts like this:
@begin[example]
cassandra%@b[ ftp odysseus]
Connected to ODYSSEUS.MIT.EDU.
220 odysseus FTP server (Version 4.103 Fri Dec 6 07:57:26 EST 1985) ready.
Name (ODYSSEUS.MIT.EDU:):@b[billb]
Password (ODYSSEUS.MIT.EDU:billb):  	  @b[<--- I enter password incorrectly.]
331 Password required for billb.
530 Login incorrect.			  @b[<--- @i(ftp) catches the error.]
Login failed.
ftp>					  @b[<--- @i(ftp) displays its command prompt.]
@end[example]

Even though the login has failed, you are still connected to the remote host.
Login to the machine with @i[ftp's] @i[user] command:
@begin[example]
ftp> @b[user]
(username) billb			  @b[<--- I enter my username.]
331 Password required for billb.
Password:				  @b[<--- I enter my password.]
230 User billb logged in.		  @b[<--- @i(ftp) logs me in.]
ftp>
@end[example]

@section[Exiting ftp]

Exit @i[ftp] with the @i[bye] command:
@begin[example]
ftp> @b[bye]
host%
@end[example]
This command disconnects you from the remote machine and
returns you to the shell on the local machine.
You can also use the @i[quit] command to exit @i[ftp]:
@i[bye] and @i[quit] are synonyms.

If you want to suspend @i[ftp] and get back to the shell,
type @i[Ctrl-Z].
Get back to @i[ftp] by typing @i[fg] to the shell.

You can also start a new shell from @i[ftp] with the @i[!]
command.
Leave the shell and return to @i[ftp] by typing @i[exit]:
@begin[example]
ftp> @b[!]
cassandra% @b[exit]
cassandra% ftp>
@end[example]

@section[Listing Files, Changing Directories, and Creating Directories
on the Remote Machine]

After you have logged in to the remote machine,
you may need to list files and change directories
before you begin the actual file transfer.
@i[ftp] has commands such as @i[ls], @i[pwd], and @i[cd],
commands work like, but differ slightly from their Unix counterparts.
@i[ls] lists files in the remote machine's current directory,
@i[pwd] prints the remote machine's current directory,
and @i[cd] changes the remote machine's current directory.

Assuming that I have connected and logged into @i[odysseus],
I can print the remote machine's current working directory with
the @i[pwd] command:
@begin[example]
ftp> @b[pwd]
251 "/mit/b/i/billb" is current directory.
ftp>
@end[example]

I can list the files and directories in my @i[odysseus] home directory
with @i[ls]:
@begin[example]
ftp> @b[ls]
200 PORT command okay.
150 Opening data connection for /bin/ls (18.72.0.122,1163) (0 bytes).
.cshrc
.emacs_keys
.emacs_vars
.history
.login
.login~
.logout
.mailrc
.mh_profile
.msgsrc
.tiprc
Mail
billb
lisp
226 Transfer complete.
128 bytes received in 0.31 seconds (0.4 Kbytes/s)
vftp>
@end[example]

The @i[ftp] @i[ls] will even give me a "long" listing of my files:
@begin[example]
ftp> @b[ls -l]
200 PORT command okay.
150 Opening data connection for /bin/ls (18.72.0.122,1164) (0 bytes).
total 14
-rw-r--r--  1 billb        1188 Dec  9 18:40 .cshrc
-rw-r--r--  1 billb           0 Oct  8  1985 .emacs_keys
-rw-r--r--  1 billb          23 Oct  8  1985 .emacs_vars
-rwxr-xr-x  1 billb          68 Apr 23 13:16 .history
-rw-r--r--  1 billb         808 Feb 11 12:47 .login
-rw-r--r--  1 billb         780 Dec  9 18:41 .login~
-rw-r--r--  1 billb          10 Oct  8  1985 .logout
-rw-r--r--  1 billb          89 Oct  8  1985 .mailrc
-rw-r--r--  1 billb         117 Oct  8  1985 .mh_profile
-rw-r--r--  1 billb           2 Feb 11 12:39 .msgsrc
-rw-r--r--  1 billb          13 Oct  8  1985 .tiprc
drwx------  2 billb         512 Oct  8  1985 Mail
drwx--x--x 12 billb        1024 Apr 23 10:41 billb
drwxr-xr-x  2 billb        1024 Apr 25 10:10 lisp
226 Transfer complete.
768 bytes received in 0.95 seconds (0.79 Kbytes/s)
ftp>
@end[example]

@section[Changing to Directories on the Remote Machine]

In the file transfer examples that follow,
I transfer lisp sourcefiles from my account on @i[odysseus]
to a directory on my workstation @i[cassandra].
Since I keep the @i[odysseus] lisp files in the @i[lisp] directory,
I need to move to that directory before I transfer files.
I use the @i[cd] command to change directories, and the @i[pwd]
comand to make sure I'm in the right place:
and the @i[ls] command to list the directory's files:
@begin[example]
ftp> @b[cd lisp]
200 CWD command okay.
ftp> @b[pwd]
251 "/mit/b/i/billb/lisp" is current directory.
ftp>
@end[example]

Although the @i[ftp] @i[cd] command appears to work just like
the Unix @i[cd] command,
the two differ slightly.
When you execute the Unix @i[cd] without specifying a directory,
the command moves you to your home directory.
@i[ftp]'s @i[cd] demands that you furnish a directory name, and
if you don't, the command will prompt you for one:
@begin[example]
ftp> cd				<--- Enter @i[cd] without an argument.
(remote-directory)		<--- @i[ftp] prompts for a directory name.
@end[example]

To change to your home directory on the remote machine,
you must be explicit:
@begin[example]
ftp> @b[cd ~billb]
200 CWD command okay.
ftp>
@end[example]

@section[Changing Directories on the Local Machine with lcd]

@i[lcd] stands for "local change directory."
Used without arguments, the command prints the local machine's
current directory:
@begin[example]
ftp> @b[lcd]
Local directory now /site/billb
ftp>
@end[example]

I change to my local @i[lisp] directory like this:
@begin[example]
ftp> @b[lcd lisp]
Local directory now /site/billb/lisp
ftp>
@end[example]

@section[Transferring Single Files with ftp]


@i[ftp] has two commands for transferring single files:
@i[get] and @i[put].
The @i[get] command transfers files from the remote machine to
the local machine,
@i[put] transfers them from the local to the remote machine.

You run the @i[get] and @i[put] commands like this:
@begin[example]
get @i[remotefile] [ @i(localfile) ]

put @i[localfile] [ @i(remotefile) ]
@end[example]
where @i[remotefile] is the filename on the local machine,
and @i[localfile] is the filename on the remote machine.
@i[localfile] is an optional argument for @i[get],
@i[remotefile] is optional for @i[put].
If you do not supply these arguments,
the file retains its original name when transferred to the new machine.

@section[Using the get Command]

Now I want to transfer a file from my @i[lisp] directory
on @i[odysseus] to my @i[lisp] directory on @i[cassandra].
I use @i[ls] to list the files in the remote @i[lisp] directory:
@begin[example]
ftp>@b[ls]
200 PORT command okay.
150 Opening data connection for /bin/ls (18.72.0.122,1165) (0 bytes).
assoc.l
count-atoms.l
factorial.l
intersect.l
pow2.l
remove.l
reverse.l
226 Transfer complete.
331 bytes received in 0.42 seconds (0.77 Kbytes/s)
ftp>
@end[example]

Suppose I want to transfer the file @i[assoc.l] from
@i[odysseus] to @i[cassandra], changing its name to @i[od-assoc.l].
I use @i[get] like this:
@begin[example]
ftp> @b[get assoc.l od-assoc.l]
200 PORT command okay.
150 Opening data connection for assoc.l (18.72.0.122,1209) (115 bytes).
226 Transfer complete.
119 bytes received in 0.01 seconds (12 Kbytes/s)
ftp>
@end[example]

@b[An Important Note!]
If you use the @i[get] command without supplying a different
filename in the second argument, and you have a file on
the local machine with a filename that matches the name of
the file being transferred,
@i[ftp] will overwrite the local file with the incoming file.
For instance,
if I do this:
@begin[example]
ftp> @b[get assoc.l]
@end[example]
and I have an @i[assoc.l] file in the current directory on @i[cassandra],
the remote @i[assoc.l] will overwrite the one on @i[cassandra].

@section[Transferring Multiple Files: mget and mput]

Use these commands to transfer multiple files.
@i(mget) retreives multiple files, @i(mput) sends them.
When you use these commands, you have the option of being
prompted for file names.
Suppose, for instance,
that I wanted to transfer all the files @i[lisp] directory
on @i[odysseus] to my lisp directory on @i[cassandra].
This is what would happen:
@begin[example]
ftp> @b[pwd]
251 "/mit/b/i/billb/lisp" is current directory.
ftp> @b[mget *]
mget assoc.l? @b[y]      <--- ftp prompts me about the file; i answer yes.
200 PORT command okay.
150 Opening data connection for assoc.l (18.72.0.122,1044) (115 bytes).
226 Transfer complete.
119 bytes received in 0.01 seconds (12 Kbytes/s)
mget count-atoms.l? @b[y] <--- ftp prompts again.
200 PORT command okay.
150 Opening data connection for count-atoms.l (18.72.0.122,1045) (219 bytes).
226 Transfer complete.
227 bytes received in 0.01 seconds (22 Kbytes/s)
mget factorial.l? @b[^C]  <--- ftp prompt again, I terminate with a Ctrl-C
ftp>
@end[example]

You can turn off the prompt facility with the @i[prompt] command:
@begin[example]
ftp> @b[prompt]
Interactive mode off.
ftp>
@end[example]
(If you use the command again, you will reenable the facility.)

Now when I use @i[mget], here's what happens:
@begin[example]
ftp> @b[mget *]
200 PORT command okay.
150 Opening data connection for intersect.l (18.72.0.122,1046) (269 bytes).
226 Transfer complete.
277 bytes received in 0 seconds (0.27 Kbytes/s)
200 PORT command okay.
150 Opening data connection for pow2.l (18.72.0.122,1047) (89 bytes).
226 Transfer complete.
92 bytes received in 0 seconds (0.09 Kbytes/s)
200 PORT command okay.
150 Opening data connection for remove.l (18.72.0.122,1048) (122 bytes).
226 Transfer complete.
126 bytes received in 0.01 seconds (12 Kbytes/s)
200 PORT command okay.
150 Opening data connection for reverse.l (18.72.0.122,1049) (169 bytes).
226 Transfer complete.
178 bytes received in 0.01 seconds (17 Kbytes/s)
ftp>
@end[example]

@i[mput], as you can imagine, works similarly.

@section[Help and Other ftp Commands]

@i[ftp] has many other commands, as well as a bare-bone help facility.
You can access help with the @i(?) command:
@begin[example]
ftp> @b[?]
Commands may be abbreviated.  Commands are:

!               debug           mdelete         sendport        send
append          dir             mdir            put             status
ascii           form            mget            pwd             struct
bell            get             mkdir           quit            tenex
binary          glob            mls             quote           trace
bye             hash            mode            recv            type
cd              help            mput            remotehelp      user
close           lcd             open            rename          verbose
delete          ls              prompt          rmdir           ?
ftp> @b[? append]
append          append to a file
ftp>
@end[example]

You can also look at the @i[ftp] man page for more details.

