Because UNIX isn’t a new phenomenon, it has many useful networking abilities built into it. In fact, UNIX was instrumental in creating much of what you now take for granted: e-mail, the Internet, and the World Wide Web. Thus, you’ll be happy to know that you can communicate over networks with the Terminal in practically any manner that you can dream of . . . and then some!
If you’ve used the Internet for any time, you’re probably familiar with the various means to transport data over a network. From FTP (short for File Transfer Protocol) and Telnet to e-mail and the web, UNIX can handle it all. In fact, UNIX has a command for each of these functions (and many more that have passed into historical obscurity).
Rather than use each individual command to send and retrieve data with the Terminal, Apple has conveniently provided a command that can handle them all: curl. The curl command is competent at all the standard network protocols. To see it in action, pass a web address (or URL, to The Enlightened) to the curl command:
curl http://www.mlcbooks.com
The result is that you see the HyperText Markup Language (HTML) page that’s located at www.mlcbooks.com. Because this isn’t particularly useful for most people (it’s not very easy to read), you need to add the letter o as a flag. This specifies where you would like to save this file upon download. To save the HTML page to your Home directory, add the -o flag and a path to the destination file.
Don’t forget to precede all flags with a hyphen. For this example, it would be -o.
curl -o ~/mlcbooks.html http://www.mlcbooks.com
If you now perform an ls command, you see that curl has, in fact, downloaded the HTML found at www.mlcbooks.com and saved it to a file named mlcbooks.html in your Home directory.
The beauty of curl is that it does much more than just retrieve web pages: It’s equally comfortable with FTP transfers. FTP is used to download (or receive) files from a server as well as upload (or send) them.
Like the previous HyperText Transfer Protocol (HTTP) examples, you only have to provide an FTP address in Uniform Resource Locator (URL) format, and curl will take care of the rest. Of course, most people want to save any files that they download via FTP — not view them in the Terminal.
Therefore, as in the previous example, you should add the -o flag and a path to the destination of your download. This time, download a README file about curl directly from the makers of curl.
curl -o ~/Desktop/README.curl ftp://ftp.sunet.se/pub/www/utilities/curl/README.curl
If you’re familiar with FTP, you might wonder whether curl can upload, too. Yes, indeed! Instead of using the -o flag, you need to use two flags: -T and -u. The -T flag denotes which file you want to upload.
The -u flag denotes the username and password. Then, specify the FTP destination address of where you want to upload it. Because this example deals with an upload, the remainder of this example is for an imaginary FTP server. In real life, you’d use the appropriate FTP address, username, and password for an FTP server where you are allowed to upload.
curl -T /Desktop/README.curl -u username:passwd ftp://ftp.yoursitehere.com
/myfiles/README.curl
This example uploads the README.curl file from the Desktop folder.
Sure, HTTP and FTP are handy, but did you know that there are many other protocols for network communications? One of the niftier ones is the Dictionary protocol. With it, you can look up words from any server that understands the protocol. Suppose, for example, that you want to know the meaning of the term DVD. Enter the following command to find out:
curl dict://dict.org/d:DVD
With curl, Dictionary, and your Dictionary Dashboard widget on the same MacBook, you might never use a real paper dictionary again!
dummies
Source:http://www.dummies.com/how-to/content/how-to-network-with-the-terminal-and-unix.html
No comments:
Post a Comment