Low End Mac Reader Specials
TypeStyler For Mac OS X is Now Shipping! Download The Free Fully Functional 60 Day Tryout at www.typestyler.com
OWC: Plug & Play Hardware RAID up to 8.0TB. High Performance, Data Redundant Solutions. FireWire 800, FireWire 400, USB2, or eSATA. Hot Swappable Bays, Data Rates over 200MB/s. Click here
Don't install Parallels to play poker online! Poker Mac will show you how
to download and install a native Mac poker application such as Full
Tilt Poker Mac.
Laptop Hardware Provided by TechRestore - Overnight Mac & iPod Repairs.
Compare products like desktop computers, apple laptops, apple macs, and LCD Monitors side by side! All the information and reviews to make the best purchasing decision for new mobile phones, sat nav systems, or MP3 players. The Ciao online shopping community makes searching products easy for you.
Linux to Mac
Automating FTP on the Mac
- 2009.03.04 - Tip Jar
Popularity: ![]()
![]()
![]()
There is no shortage of GUI FTP programs, but kicking it old school on the command line allows you to easily automate uploads and downloads. The best part is, there is nothing to install. Everything you need waits patiently behind the warm glow of a Terminal session.
The Mac Command Line FTP Program
The default command line FTP program in OS X 10.5 resides at /usr/bin/ftp
By all outward appearances and behavior, the Mac FTP program is the standard BSD version. The man page is the standard BSD main page and contains a wealth of useful information.
A typical command line FTP session is interactive and goes something like this:
- login to an FTP server
- issue commands (ls (list), get (download), put (upload))
- quit
If you have a repetitive FTP task, the fun quickly fades into a mind numbing exercise. This is where FTP automation shines.
The Magical .netrc File
What makes FTP automation possible is a magical, little known file called .netrc. The .netrc file is a plain text file that is hidden (the file name starts with a period) and lives in the root of your home directory. The .netrc file allows FTP to perform automatic logins to FTP servers based on the name.
The .netrc is not created by default. You have to create it manually. To create an empty .netrc file, open a Terminal and use the following commands:touch .netrc chmod 700 .netrc
It is critical that you issue the chmod command to set the permissions so that only the owner of the file can view it. If the permissions are not set correctly, the FTP client will assume it has been compromised and will refuse to use it.
Inside the .netrc, you define a block of settings for each FTP server you use, including the machine name, the login ID, and the password. Here is a typical block for a mythical FTP server:
machine myftpserver.com login myuser password mypasswordThere are additional settings that can be included. Check the FTP man page for more. You can test your settings by typing "ftp myftpserver.com" at a Terminal prompt, and it should automatically login. Note that you can store multiple FTP server logins in the .netrc file.
Sending FTP Commands from a BASH Shell Script
Once logins are automated, the final piece of the puzzle is to script a set of FTP commands. The following example uses an advanced BASH shell scripting technique called a "here" document to group the FTP commands to be sent to the server.
#!/bin/bash /usr/bin/ftp -d myftpserver.com << ftpEOF prompt put "*.html" quit ftpEOF
The FTP command is issued with the -d flag (debug mode) to make it more verbose. That makes any kind of error more obvious. The connection is made to myftpserver.com using the ID and password from the .netrc file. Once the connection is made, the rest of the commands are issued one at a time until the end of the "here" document at the second "ftpEOF". Note that any valid FTP commands can be sent. In the example, the prompt command tells FTP not to prompt for multiple file operations, then the put uploads all files with an .html extension. If you want to go the extra mile, you can extend the shell script and do things like reconnect to the FTP server to verify the file sizes of your uploads.
While there are several ways you can automate FTP, the nice thing
about this method is that it is portable to Linux or any other Unix
system.
Keith Winston is a recent Mac convert after five years of Linux on the desktop. He also writes for Linux.com and created CommandLineMac to focus on the Unix-y power of the Mac. If you find Keith's articles helpful, please consider making a donation to his tip jar.
Recent Linux to Mac Columns
- Automount OS X Home Directories Using OpenLDAP and Linux, 09.28. It's possible to get an OS X Mac to automatically mount a Linux server using OpenLDAP. The tricky part is finding all the steps needed to make it work.
- Introduction to Autofs in Mac OS X, 07.01. "Autofs is often used in enterprise environments to set up network-based home directories and other network mounts for users at login."
- An RSS News Reader with the Power of Google, 08.20. Unlike browser-based RSS readers or dedicated news reader apps, Google Reader lets you access your favorite feeds from any computer and browser.
- 3 reasons to run virtualized Linux, 05.22. Reasons to run Linux under virtualization include duplicating your development environment, X11 programs that don't work well in OS X, and exploring different GUI concepts.
- More in the Linux to Mac index.
Links for the Day
- Mac of the Day: iMac Core Duo, Jan. 2006 - The first Intel-based iMacs ran at 1.83-2.0 GHz, came with 17" and 20" displays.
- Group of the Day: Mac Pro List is for those using a Mac Pro.
- November 23 in LEM history: 99: Should I buy a USB card? - 01: Can a low-end Mac be an only Mac? - Palm Desktop without a PDA - CyberDog saves the day - 05: How Consumer Reports could compare Macs fairly - Speakers for your Mac - Living with the hi-res 15" PowerBook - Birth of the PowerBook - Daystar 1.9 GHz iMac G4 upgrade - 1.92 GHz PowerBook upgrade
- Support Low End Mac
Recent Content on Low End Mac
- Apple's Tablet an End Run Beyond Netbooks, Frank Fox, Stop the Noiz, 11.20. Whatever Apple has planned will leverage existing technologies while going beyond what its competitors can offer.
- i5 iMac Benchmarked, Mac mini 'Shouldn't Be Overlooked', Twitter Client for Classic Mac OS, and More, Mac News Review, 11.20. Also why Apple leaves the low end to others, 10.6.2 fixes video playback problem in 27" iMac, 3D Leopard and Snow Leopard performance, and more.
- Apple #4 in Reliability, Apple Tablet a Gadget for All?, HP's i7 Notebook Outdoes Mac Rivals, and More, The 'Book Review, 11.20. Also Flash 10.1 improves video on Hackintosh netbooks, thin-and-light notebooks impress, Windows XP finally on the way out, and more.
- NASA Chemical Sensor for iPhone, Smartphone Death Match, iPhone Earrings, and More, Ian R Campbell, 11.20. Also mobile phone dangers, new apps, GPS solution for iPod touch, new iPod and iPhone cases, and more.
- Replacing the Hard Drive in a Clamshell iBook, John Hatchett, Recycled Computing, 11.19. Yes, it is one of the most difficult Apple notebooks to disassemble and reassemble, but a 10 GB hard drive just will not do.
- IBM Model F: A Great Old Keyboard with an Outdated Layout, Tommy Thomas, Welcome to Macintosh, 11.19. Although it used a different technology than the revered IBM Model M keyboard, the Model F was a great keyboard in its own right.
- Soft Touch Keyboards, Wireless Mouse Options, Loving SeaMonkey 2, and More, Charles W. Moore, Miscellaneous Ramblings, 11.18. Also the future of browsing with PowerPC Macs and the multiple mouse input bug introduced with OS X 10.5.8.
- More links in our archive.
Recent Deals
- Best eMac Deals, 11.18. Used 1 GHz Combo, $100; SuperDrive, $269; 1.25 GHz Combo, $119; SD, $319; 1.42 GHz Combo, $289; SD, $498.
- Best Mac OS X 10.6 and Mac Box Set Deals, 11.18. "Snow Leopard", single user, $25; 5 users, $45; Mac Box Set, single user, $139; 5 users, $180; Server, $414. Shipping included.
- Best Xserve Deals, 11.18. Used 1 GHz dual G4, $649; 2.3 dual G5, $795; 3.0 4-core Xeon, $1,899; refurb 2.26 4-core, $2,499; new, $2,888; refurb 8-core, $2,999; new, $3,449; more.
- Best 15" MacBook Pro Deals, 11.17. Used 1.83 GHz, $750; 2.16, $800; 2.33, $900; refurb 2.4, $1,299; 2.53, $1,449; 2.66, $1,699; 2.8, $1,899; new 2.53, $1,579; 2.66, $1,799; more.
- Best Power Mac G4 and AGP Video Card Deals, 11.17. Used 400 MHz, $50; 933 MHz, $80; 500 dual, $60; 867 dual, $90; 1 GHz dual, $150; 1.25 GHz dual, $225; 1.42 GHz, $499.
- Best Mac OS X 10.5 Deals, 11.17. "Leopard" upgrade, $80; single user license, $135; 5 users, $173; Mac Box Set, 5 users, $230; Server, 10 users, $340; unlimited, $850. Shipping included.
- Best Mac mini Deals, 11.16. Used 1.42 GHz G4 mini, $379; 1.66 GHz Core Solo, $419; 2.0 Core 2, $450; new 2.26 GHz nVidia, $580; 2.53 GHz, $769; Server, $990.
- Best iBook G4 Deals, 11.16. Used 12" 1.07 GHz Combo, $210; 1.33 GHz, $298; 14" 1.33 GHz, $398; 1.42 GHz, $479; SuperDrive, $498.
- Best iPod shuffle Deals, 11.16. Used 1 GB, $35; 4 GB, $65; refurb 1 GB, $39; 2 GB, $59; new 2 GB, $55, 4 GB, $75. New and refurb prices include shipping.
- More deals in our archive.
About LEM | Support | Usage | Privacy | Contacts
Navigation
Used Mac Dealers
Apple History
Video Cards
Email Lists
Favorite Sites
MacSurfer
MacMinute
MacInTouch
MyAppleMenu
InfoMac
Macs Only!
The Mac Observer
Accelerate Your Mac
RetroMacCast
PB Central
MacWindows
The Vintage Mac
Museum
DealMac
DealsOnTheWeb
Mac2Sell
ramseeker
Mac Driver Museum
JAG's House
System
6 Heaven
System 7 Today
the pickle's Low-End
Mac FAQ
Abandonware
Petition
Mac vs. PC Info
Affiliates
The Apple
Store
Mac
Connection
B&H
MacMall
TechRestore
ExperCom
Crucial
Memory
batteries.com
Advertise
MacMinute
MacInTouch
MyAppleMenu
InfoMac
Macs Only!
The Mac Observer
Accelerate Your Mac
RetroMacCast
PB Central
MacWindows
The Vintage Mac
Museum
DealMac
DealsOnTheWeb
Mac2Sell
ramseeker
Mac Driver Museum
JAG's House
System 6 Heaven
System 7 Today
the pickle's Low-End
Mac FAQ
Abandonware
Petition
Mac vs. PC Info
Mac Connection
B&H
MacMall
TechRestore
ExperCom
Crucial Memory
batteries.com
