<<

. 31
( 69 .)



>>

sometimes any string of characters) as your password.
telnet, the ftp command has been enabling Unix users
Anonymous ftp allows people who do not have accounts
to upload and download files for a couple of decades. The
on a system to upload or download files. For example, if
protocol, or language, of ftp is fairly simple, although some
you set up a drop box for your customers to upload error
ftp servers have implemented a wide range of commands.
logs so you can analyze problems they are having with
software you sold them, you might chose anonymous ftp.
In its simplest form, ftp allows you to log on to a system,
Many companies, such as Apple, that provide
upload files using the put command, download files using
documentation and software tools to their customers do so
the get command, and move around the directory
using anonymous ftp.
structure on the remote system. You can transfer data in
binary mode or ASCII mode. ASCII mode is designed for
You should cd into the directory in which you want
text files, and ftp translates line endings if you are
downloaded files stored before you start your ftp session.
transferring text files between Unix and DOS systems.
Like telnet, ftp is not enabled as a service on Mac OS X
Binary mode is designed for software, image files, and other
when you first install the operating system.
types of files that use non-printable characters that might
otherwise interfere with the transfer.



TRANSFER FILES




– The file downloads.
¤ Type the name of the › Type ascii and press
Note: You must be connected to the
Internet for this task. system from which you want Return.
to download files and press
„ Type ftp followed by a ˇ Type get, a space, the
Return.
space. name of a text file, and then
‹ Type your username and press Return.
password at the prompts and
press Return.

146
10
WORK WITH INTERNET COMMANDS


You will have an easier time figuring out what went wrong in a file transfer if you know
what to look for. Files that you download incorrectly will have problems. Binary files that
you transfer as if they are text files are likely to be corrupt and probably unusable. If you
attempt to display or otherwise use the files, the system will display an error message.
Text files that you download as binary are likely to be fine if you download them from
another Unix system. However, a text file that you download in binary mode from a
Windows system is likely to have an extra character at the end of every line. This character
represents the carriage return that Unix systems do not use. It displays as ^M when you
open these files with an editor.

Example:
Making Better Use of Ping^M
^M
Long one of the system administrator's favorite tools for^M
troubleshooting network-related problems, ping is used^M

You can remove these unwanted characters using the Unix tr command.

Example:
[ferro:˜] cat textfile | tr -d "\015" > textfile$$
[ferro:˜] mv textfile$$ textfile




Á Type binary and press ‡ Type get, a space, the ‹ Type ls and press Return.
USING ANONYMOUS FTP
Return. name of a binary file, and
„ Type ftp ftp apple.com and – The system displays a list
then press Return.
press Return. of directories.
– The file downloads. ¤ Type anonymous at the › Type bye and press Return
login prompt and your e-mail to log off.
address at the password
prompt, each time pressing
Return.
147
UNIX FOR MAC


ACCESS ANOTHER COMPUTER SECURELY
ssh server such as sshd. For some ssh connections, you

Y
ou can log on to a remote system more securely than
will log on with username/password pairs. For others, you
with telnet by using ssh. The telnet, rlogin, and
may be provided with a digital certificate. If your username
ftp commands have a long-recognized vulnerability.
is not the same on both systems, you must use the “l
Each of these commands transmits usernames and
option.
passwords in clear text. Anyone situated along the network
path between you and the system you are logging on to and
From a user's point of view, using ssh in place of telnet or
capable of "sniffing" packets ” capturing network traffic
rlogin makes little difference. The process and the result
intended for another system ” could capture your logon
are nearly the same, especially if the user logs on with a
information and use your account. For this reason, secure
username and password. The encryption and decryption
tools have been created that provide remote logon access
securing the transferred information is completely
and file transfer without exposing username and password
transparent. When digital certificates are installed on the
information. These tools use a process known as encryption
client and server end of a connection, the process of logging
to make the network traffic between client and server
on may be simplified even further. However, the logon only
indecipherable.
works on systems that have had the certificates installed.
To use ssh in place of telnet or rlogin, you need to
Similarly, you can use sftp in place of ftp to securely
have access to an ssh command or a tool that uses ssh,
transfer files. When you use sftp, the files you download
and the server that you want to connect to must have an
are encrypted during the download.

ACCESS ANOTHER COMPUTER SECURELY




¤ Type the name of a ‹ Type the name of the
LOG ON WITH SSH LOG ON WHEN YOUR
USERNAMES DO NOT MATCH
server for which you have an remote system and press
Note: You must be connected to the
„ Type ssh -l followed by a
account and that has an ssh Return.
Internet for these tasks.
server running, and press space. › Type your password at the
„ Type ssh followed by a Return.
¤ Type your username for prompt and press Return.
space.
‹ Type your password at the the remote system followed – You are logged on to the
prompts. by a space. server.
– You are logged on to the
server.
148
10
WORK WITH INTERNET COMMANDS



If you need a file that is on a remote system and
your are limited to using secure connections, you
can still download files, but you must use sftp
instead of ftp. When you use sftp, your download
files are encrypted between the remote server and
your system, making it safer to download sensitive
files. You can download a file using sftp in the way
just described or by entering a one-line command
in a Terminal window. Type the line shown below,
replacing the portions of the command in brackets
with your data.

Example:
[ferro:˜] user% sftp user@remote.system.net:
/home/user/myfile.txt
Connecting to remote.system.net...
user@remote.system.net's password:
Fetching /home/user/myfile.txt to myfile.txt




‹ Type the name of the ˇ Type ls and press Return ‡ Type the name of a text
TRANSFER FILES SECURELY
remote system and press to display a list of the files in file and press Return to
„ Type sftp followed by a Return. the remote account. download the file.
space.
› Type your password at the Á Type get followed by a ° Type bye to exit.
¤ Type your username prompt. space.
followed by @.
– You are logged on with
sftp.


149
UNIX FOR MAC



DOWNLOAD WEB FILES
To use curl, you type curl followed by any of the options

Y
ou can download files with very little effort by using
that you want to specify and the URL string. A command such
the curl command. Although the most obvious way
as curl -O http://www.sandrich.com/index.html
to download a Web page is to type or copy the URL
copies the specified file from the specified site to your
in your browser's Address block and use the Save As
current directory using the same filename. Without the -O,
feature, this is not necessarily the easiest or most efficient
the curl command downloads the file to your screen and
method. Mac OS X includes a command line tool called
presents you with lines of HTML.
curl ” copy URL ” for downloading Web pages. Curl
works with a number of protocols, including HTTP, HTTPS,
Curl allows you to copy more than Web pages. You can
FTP, GOPHER, DICT, TELNET, LDAP, and FILE.
also use it to download binary files, including image files
and software. In fact, the command is so efficient that Unix
Not only does curl allow you to download Web pages on
tools designed to locate and download applications from
the command line, but it also allows you to download files
the Internet often use curl to do the downloading. You can
using curl commands in a script. In fact, you can
specify multiple URLs or portions of URLs by enclosing
download and install files in a completely unmanned
the strings you want to match within braces. The string
fashion. The syntax of the curl command is flexible
www.{a,b,c).com, for example refers to the three systems ”
enough to allow you to access multiple pages or multiple
www.a.com, www.b.com, and www.c.com.
sites with a single command.



DOWNLOAD WEB FILES




¤ Type -O followed by a ‹ Type a URL containing a
COPY A WEB PAGE COPY A RANGE OF WEB PAGES
space. range and press Return.
„ Type curl followed by a
Note: You must be connected to the
– The specified pages
‹ Type the URL of a Web
Internet for these tasks. space.
page and press Return. download.
„ In the Terminal window, ¤ Type -O followed by a
– The page downloads and
type curl followed by a space. space.
maintains the same filename.


150
10
WORK WITH INTERNET COMMANDS



Curl can post to Web sites as well as download files of various kinds.
Posting commands include the name of the script to be executed along
with the parameters that you would enter in the online form. You need
to know quite a bit about a form to successfully post to it. The example
below assumes that the parameters birthyear and vote are being
collected by the online form. It also assumes that the data is processed
when a button is pressed and that the value of the press equals OK.
A post command in curl might look like the following:

curl -d "birthyear=1985&vote=1&press=OK" www.site.com/vote.cgi

<<

. 31
( 69 .)



>>