

Once you have the scripts, you can simply type.

Using this as a model, you can see that a number of variations are possible, for both uploading and downloading files.
Mac os x shell script editor password#
netrc file is needed because the FTP program will not (for security reasons, I believe) accept username and password within the context of a "here" document. This is somewhat of a security hole, so you should immediately change the permissions on the file so that only you can see it: chmod go-rwx. netrc file has your password in it, in plaintext. Password yourPWORDObviously, replace 'yourISP', 'yourUNAME', and 'yourPWORD' with your ISP, username, and password. netrcInside the editor, insert the following lines: machine login yourUNAME Follow these steps to create the file: cd ~ netrc in the top level of your home directory. The next (and last) step is the creation of a file called.

First, you'll need to make your script executable: chmod ugo+x siteup.xfrThis adds execute permissions to the file. To actually make this work, however, there are two more steps. I tell FTP to open the connection, switch to the right directory, set ASCII mode, send the "server is up" HTML page, and disconnect.Įcho FTP ended - your web site is now marked as UP.Īnother statement that will show up in the terminal window. Within the here document, everything between ftp Launch FTP and tell the script to treat the following section as "here" text.Ĭustomize these to match your FTP site. This message will display in the terminal window.Ī "here" document is what makes this script possible. This is a shell script (as opposed to a perl script or some other type). Put /Users/robg/Documents/siteup.html index.htmlĮcho FTP ended - your web site is now marked as UP.Looking line by line, here's what the script does. The name and extension aren't that important, so pick one that you like: vi siteup.xfrThis example script takes an HTML file from the same directory that we're working in, and uploads it to the ISP as the new 'index.html' file.Įnter the following information into the editor see the comments following the text for and explanation of each line. Once in the proper directory, start an editor for the new file. For this example, I'm saving it in /Users/robg/Documents. To create these script(s), open a terminal and navigate to the directory where you'd like the script to live.
Mac os x shell script editor how to#
Read the rest if you'd like to see how to set up a simple automated FTP script. This tutorial requires some basic understanding of the command line and an OS X text editor such as vi or pico. I manage both these tasks with a double-click on an icon in the finder, thanks to these scripts. This way, our family and friends can tell easily if the site is up or not. When I return to OS X, I upload a "Our server is up" page.

Before I shut down OS X, I upload a "Our server is down" page to my ISP-hosted site. Since my home machine is occasinally out of OS X, that means that my family's OS X hosted website is not accessible. Although similar things are probably possible with grapical clients, this will teach you a bit about UNIX and a very basic shell script. If you often transfer the same file to/from an FTP server (or do anything repetitively with an FTP server), you can use UNIX and a simple script to automate the process.
