Unix on Panther: Accessing the Internet
Pages: 1, 2, 3
SFTP: FTP to secure sites
If you can only use ssh to connect to a remote
site, chances are it won't support regular FTP transactions either, probably due
to higher security. Mac OS X also includes a version of ftp that is
compatible with the standard SSH server programs and works identically to
regular FTP. Just type sftp at the command line. Here's an
example:
$ cd downloads
$ sftp taylor@intuitive.com
Connecting to intuitive.com...
The authenticity of host 'intuitive.com (128.121.96.234)' can't be
established.
RSA key fingerprint is d0:db:8a:cb:74:c8:37:e4:9e:71:fc:7a:eb:d6:40:81.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'intuitive.com,128.121.96.234' (RSA) to the list
of known hosts.
taylor@intuitive.com's password:
sftp> cd mybin
sftp> dir -l
drwxr-xr-x 0 24810 100 1024 Jun 26 20:18 .
drwxr-xr-x 0 24810 100 1536 Sep 16 18:59 ..
-rw-r--r-- 0 24810 100 140 Jan 17 2003 .library.account.
info
-rwxr-xr-x 0 24810 100 3312 Jan 27 2003 addvirtual
...
-rw-r--r-- 0 24810 100 406 Jan 24 2003 trimmailbox.sh
-rwxr-xr-x 0 24810 100 1841 Jan 24 2003 unpacker
-rwxr-xr-x 0 24810 100 946 Jan 22 2003
webspell
sftp> get webspell
webspell 100% 946 4.7KB/s 00:00
sftp> quit
$ ls -l webspell
-rwxr-xr-x 1 taylor taylor 946 25 Sep 11:28 webspell
FTP with a web browser
If you need a file from a remote site, and
you don't need all the control that you get with the ftp program,
you can use a web browser to download files using anonymous FTP. To do that,
make a URL (location) with this syntax:
ftp://hostname/pathname
For instance, ftp://somecorp.za/pub/reports/2001.pdf specifies the file 2001.pdf from the directory /pub/reports on the host somecorp.za. In most cases, you can also start with just the first part of the URL—such as ftp://somecorp.za—and browse your way through the FTP directory tree to find what you want. If your web browser doesn't prompt you to save a file, use its Save menu command.
NOTE: If you are using the Safari browser, it will open ftp: directories by mounting them in the Finder.
An even faster way to download a file is with the
curl (copy from URL) command. For example, to save a copy of the
report in the current directory, simply enter:
$ curl -O ftp://somecorp.za/pub/reports/2001.pdf
Without the -O option, curl will display the file
in the Terminal window. If you want to read a text file from an Internet server,
you can combine curl and less:
$ curl ftp://ftp.oreilly.com/pub/README.ftp | less
You can also use curl with web pages, but this will bring the
page up in HTML source view:
$ curl http://www.oreilly.com | less
Other FTP solutions
One of the pleasures of working with Unix within the Mac OS X environment is that there are a wealth of great Aqua applications. In the world of FTP-based file transfer, the choices are all uniformly excellent, starting with Fetch, NetFinder, Transmit, FTPeel, rbrowser, and Anarchie, and encompassing many other possibilities. Either open the Apple menu and select "Get Mac OS X Software . . . ", or try VersionTracker (see http://www.versiontracker.com/), Mac OS X Apps (see http://www.macosxapps.com/), MacUpdate (see http://macupdate.com/), or the shareware archive site Download.com (see http://www.download.com/).
Easy Shortcuts with Connect to Server
The Terminal application has a
very helpful feature that can make connecting to remote systems via
telnet, ssh, ftp, or sftp a
breeze, once it's set up. Connect To Server is available off the File menu and
is shown in Figure
8-4.

Figure 8-4. Connect to Server offers simple shortcuts
To add a service, click on the + icon on the left side of the window. More commonly, you'll add servers, which you can do by clicking on the + icon on the right side of the window. It produces a window that asks for the hostname or host IP address, which is easily entered, as shown in Figure 8-5.

Figure 8-5. Adding a New Server to Connect to Server
Once added in one area, the new server is available for all services, so to
connect to Apple's anonymous FTP archive site, choose ftp, then the
new server name, and then enter ftp into the User box, as
shown in Figure
8-6.

Figure 8-6. Specifying user ftp on ftp connections to
ftp.apple.com
Finally, the connection to Apple's server is a breeze: specify the server, specify the user, and click on Connect. The results are shown in Figure 8-7.

Figure 8-7. Instant connection to Apple's ftp server
Practice
You can practice your ftp skills by connecting to the public FTP
archive ftp.apple.com. Log in as ftp with your email address
as the password, then look around. Try downloading a research paper or document.
If you have an account on a remote system, try using rcp and
scp to copy files back and forth.
Footnotes
[1] In
ssh, you can run an agent program, such asssh-agent, that asks for your passphrase once, then handles authentication every time you runsshorscpafterward.[2] Quotes tell the local shell not to interpret special characters, such as wildcards, in the filename. The wildcards are passed, unquoted, to the remote shell, which interprets them there.
Dave Taylor is a popular writer, teacher and speaker of business and technology issues. The founder of The Internet Mall and iTrack.com, he's been involved with UNIX and the Internet since 1980. He's also been a Mac fan since the year it was released.
Brian Jepson is an O'Reilly editor, programmer, and co-author of Mac OS X Panther for Unix Geeks and Learning Unix for Mac OS X Panther. He's also a volunteer system administrator and all-around geek for AS220, a non-profit arts center in Providence, Rhode Island. AS220 gives Rhode Island artists uncensored and unjuried forums for their work. These forums include galleries, performance space, and publications. Brian sees to it that technology, especially free software, supports that mission. You can follow Brian's blog here.
Return to Mac DevCenter
You must be logged in to the O'Reilly Network to post a talkback.
Showing messages 1 through 15 of 15.
-
OpenSSH is a godsend
2004-03-31 11:58:21 csoto [Reply | View]
I do so much more remotely because SSH and X11 are available on X.
Another useful tool: http://www.sshkeychain.org/
-
SCP paths and spaces
2004-03-29 13:48:21 epistemos [Reply | View]
Nice article.
I have been trying to solve the problem of using scp to copy file with spaces in the path name, I have not been able to get quotes to work, any suggestions.
-travis n -
SCP paths and spaces
2004-03-29 16:52:26 alantech [Reply | View]
Have you tried prefacing the spaces with backslashes (\) instead of quoting the pathname? -
SCP paths and spaces
2004-03-30 13:54:35 epistemos [Reply | View]
Hello,
Yes, I have tried escaping the spaces individually as well, with single and double backslashes.
Have you gotten such to work?
Thanks.
-travis n -
SCP paths and spaces
2004-05-19 03:10:07 pxmatt [Reply | View]
You need to escape the remote path with both backslashes *and* double-quotes, see here for a more detailed explanation:
http://www.dansanderson.com/blog/view.php3?entry_id=03319
-
routers? How to access?
2004-03-29 07:43:05 kms007 [Reply | View]
What if your LAN machines are behind a router and you'd like to be able to access them from outside? Will ssh work? Are there any settings that need to be made on the router in order to access your machine?
Thanks!
-
routers? How to access?
2004-03-29 07:48:24 Brian Jepson |
[Reply | View]
You can do this. Suppose you have an AirPort Extreme base station. You could configure it to hand out DHCP addresses up to a limit such as 192.168.254.148, but set up a network location on your desktop Mac with a fixed IP address above that range. Then, use the AirPort Admin Utility to forward SSH (port 22) to that machine.
To set this up, select Show All Settings, then click Port Mapping to specify a public port (what the outside world connects to), as well as the private address and port. People outside your network need to connect to the Public (WAN) address shown in the Show Summary screen.
If you have a non-AirPort base station, see the manual that came with it for instructions. -
routers? How to access?
2004-03-29 07:59:49 kms007 [Reply | View]
Thanks, bjepson - I have a LinkSys Cable/DSL router (BEFSR41) -- I've gone through the manual, but it is a bit confusing to me.
Here's what I know:
My cable modem provides a DHCP address to me. Looking at the web based router management utility, I can see that I have both a WAN and a LAN address. Will the WAN address work? The utility also mentions something called Remote Management -- currently it's disabled. Should I enable it? Sorry for my lack of knowledge on the subject, and thanks for your help! -
routers? How to access?
2004-03-29 08:02:38 Brian Jepson |
[Reply | View]
-
routers? How to access?
2004-03-29 08:22:26 kms007 [Reply | View]
Many Thanks! :)
I've made the appropriate config settings as per the document (and I also have a static IP assigned behind my router now, thanks to another Linksys knowledgebase article I found.) Hopefully it will all work once I test it out from work. :)
Are there any specific port(s) for using applications like Remote Desktop or Timbuktu?
-
routers? How to access?
2004-03-29 09:17:12 Brian Jepson |
[Reply | View]
Glad it worked! I don't know the ports that Remote Desktop and Timbuktu use, you'll have to Google for them. -
routers? How to access?
2004-03-30 04:36:57 kms007 [Reply | View]
Yay! I was finally able to ssh into my machine from work. I found a useful website called no-ip.com that assigns a pseudo name that's easy to remember instead of having to remember the WAN IP address if your cable modem/DSL switches it every few days.






You have to copy the file first and then the resource fork:
Another way that may work is to package the file in an archive before copying it.
One thing I didn't find a way to do yet is to scp a file which contains colons ":" in its name. Escaping the colons no single quoting the file name does not works.