Unix on Panther: Accessing the Internet
Pages: 1, 2, 3
Transferring Files
You may need to copy files between
computers. For instance, you can put a backup copy of an important file you're
editing onto an account at a computer in another building or another city. Or,
Dr. Nelson could put a copy of a data file from her local computer onto a
central computer, where her colleagues can access it. Or you might want to
download 20 files from an FTP server, but not want to go through the tedious
process of clicking on them one by one in a web browser window. If you need to
do this sort of thing often, you may be able to set up a networked filesystem
connection; then you'll be able to use the Finder or local programs such as
cp and mv. But Unix systems also have command-line
tools for transferring files between computers. These often work more quickly
than graphical tools. We explore them later in this section.
scp and rcp
Mac OS X includes both
scp (secure copy) and rcp (remote copy) programs for
copying files between two computers. In general, you must have accounts on both
computers to use these. The syntax of scp and rcp are
similar to cp, but also let you add the remote hostname to the
start of a file or directory pathname. The syntax of each argument is: hostname:pathname
hostname: is needed only for remote files. You can copy from a
remote computer to the local computer, from the local computer to a remote
computer, or between two remote computers.
The scp program is much more secure than rcp, so we
suggest using scp to transfer private files over insecure networks
such as the Internet. For privacy, scp encrypts the file and your
passphrase.
For example, let's copy the files report.may and
report.june from your home directory on the computer named
giraffe.intuitive.com and put the copies into your working directory
(.) on the machine you're presently logged in to. If you haven't set up the SSH
agent that lets you use scp without typing your passphrase,
scp will ask you:
$ scp giraffe.intuitive.com:report.may giraffe.intuitive.com:report.june .
Enter passphrase for RSA key 'taylor@mac':
To use wildcards in the remote filenames, put quotation marks ("name") around each remote name.[2]
You can use absolute or relative pathnames; if you use relative pathnames, they
start from your home directory on the remote system. For example, to copy all
files from your food/lunch subdirectory on your giraffe
account into your working directory (.) on the local account, enter: $ scp "giraffe.intuitive.com:food/lunch/*" .
Unlike cp, the Mac OS X versions of scp and
rcp don't have an -i safety option. If the files
you're copying already exist on the destination system (in the previous example,
that's your local machine), those files are overwritten.
If your system has rcp, your system administrator may not want
you to use it for system security reasons. Another program, ftp, is
more flexible and secure than rcp (but much less secure than
scp).
FTP
FTP, or file transfer protocol, is a
standard way to transfer files between two computers. Many users of earlier Mac
OS versions are familiar with Fetch (http://fetchsoftworks.com/), a shareware
graphical FTP client that runs on Mac OS X as well as earlier versions.
The Unix ftp program does FTP transfers from the command line.
There are also a number of easy-to-use graphical FTP tools available from the
Apple web site (go to "Get Mac OS X Software . . . " from the Apple menu and
click on Internet Utilities). But we cover the standard ftp program
here. The computers on either end of the FTP connection must be connected by a
network (such as the Internet).
To start FTP, identify yourself to the remote computer by giving the username
and password for your account on that remote system. Unfortunately, sending your
username and password over a public network means that snoopers might see
them—and use them to log into your account on that system.
A special kind of FTP,
anonymous FTP, happens if you log into the remote server with the
username anonymous. The password is your email address, such as
alex@foo.co.uk. (The password isn't usually required; it's a courtesy
to the remote server.) Anonymous FTP lets anyone log into a remote system and
download publicly accessible files to their local systems. Here's how that might
look: $ ftp ftp.apple.com
Trying 17.254.16.11...
Connected to ftp.apple.com.
220 ProFTPD 1.2.8 Server (Apple Anonymous FTP Server) [ftp02.apple.com]
Name (ftp.apple.com:taylor): ftp
331 Anonymous login ok, send your complete email address as your password.
Password:
230 Anonymous access granted, restrictions apply.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> dir
500 EPSV not understood
227 Entering Passive Mode (17,254,16,11,223,250).
150 Opening ASCII mode data connection for file list
drwxrwxrwx 3 ftpprod ftpprod 102 May 7 19:11 Apple_Support_Area
drwxrwxr-x 20 ftpprod ftpprod 680 Aug 28 22:07 developer
drwxrwxr-x 30 ftpprod ftpprod 1020 Sep 15 13:44 emagic
drwxrwxr-x 10 ftpprod ftpprod 340 Sep 3 16:23 filemaker
drwxrwxrwx 10 ftpprod ftpprod 340 Apr 7 16:50 research
226 Transfer complete.
ftp> quit
221 Goodbye.
$
Command-line ftp
To start the standard Unix ftp program, provide
the remote computer's hostname: ftp hostname
ftp prompts for your username and password on the remote
computer. This is something like a remote login (see Section
8.1, earlier in this chapter), but ftp doesn't start your usual
shell. Instead, ftp prints its own prompt and uses a special set of
commands for transferring files. Table
8-1 lists the most important ftp commands.
Table 8-1. Some ftp commands
|
Command |
Description |
|
put filename
|
Copies the file filename from your local
computer to the remote computer. If you give a second argument, the remote
copy will have that name. |
|
mput filenames
|
Copies the named files (you can use wildcards) from the local computer
to the remote computer. |
|
get filename
|
Copies the file filename from the remote
computer to your local computer. If you give a second argument, the local
copy will have that name. |
|
mget filenames
|
Copies the named files (you can use wildcards) from the remote computer
to the local computer. |
|
prompt
|
A "toggle" command that turns prompting on or off during transfers with
the mget and mput commands. By default,
mget and mput will prompt you "mget
filename?" or "mput filename?" before transferring each file; you
answer y or n each time. Typing
prompt once, from an ftp> prompt, stops the
prompting; all files will be transferred without question until the end of
the ftp session. Or, if prompting is off, typing
prompt at an ftp> prompt resumes
prompting. |
|
hash
|
Displays progress marks on file uploads and downloads so you can gauge
progress. Particularly helpful with large transfers. |
|
cd pathname
|
Changes the working directory on the remote machine to pathname (ftp typically starts at your
home directory on the remote machine). |
|
lcd pathname
|
Changes ftp's working directory on the local
machine to pathname. (ftp's first
local working directory is the same working directory from which you
started the program.) Note that the ftp lcd command changes
only ftp's working directory. After you quit
ftp, your shell's working directory will not have
changed. |
|
dir
|
Lists the remote directory (like ls -l). |
|
binary
|
Tells ftp to copy the file(s) that follow it without
translation. This preserves pictures, sound, or other data. |
|
ascii
|
Transfers plain-text files, translating data if needed. For instance,
during transfers between a Microsoft Windows system (which adds Control-M
to the end of each line of text) and a Unix system (which doesn't), an
ascii-mode transfer removes or adds those characters as
needed. |
passive
|
Toggles the setting of passive mode. This may help ftp to run correctly
if you are behind a firewall. If you put the command setenv
FTP_PASSIVE 1 in your .tcshrc, all your ftp sessions will
use passive mode. |
|
quit
|
Ends the ftp session and takes you back to a shell
prompt. |
Here's an example. Carol moves into the local directory she wants to use as a
starting point (a good idea whether you're uploading or downloading), then uses
ftp to copy the file todo from her work
subdirectory on her account on the remote computer rhino: $ cd uploads
$ ls
afile ch2 somefile
$ ftp rhino.zoo.edu
Connected to rhino.zoo.edu.
Name (rhino:carol): csmith
Password:
ftp> cd work
ftp> dir
total 3
-rw-r--r-- 1 csmith mgmt 47 Feb 5 2001 for.ed
-rw-r--r-- 1 csmith mgmt 264 Oct 11 12:18 message
-rw-r--r-- 1 csmith mgmt 724 Nov 20 14:53 todo
ftp> get todo
local: todo remote: todo
227 Entering Passive Mode (17,254,16,11,224,18).
150 Opening BINARY mode data connection for todo (724 bytes)
226 Transfer complete.
724 bytes received in 00:00 (94.06 KB/s)
ftp> quit
$ ls
afile ch2 somefile todo
We've explored the most basic ftp commands here. Entering help at an ftp> prompt gives a list
of all commands; entering help followed by an ftp
command name gives a one-line summary of that command.
Pages: 1, 2, 3
|
Next Page |

|