How can I automate an SFTP file upload to my web server?
September 1, 2012 8:14 PM   Subscribe

I want to automatically upload a file via ssh or sftp to a web server whenever it is modified.

I used to use an old application called Kung-Tunes to upload a formatted html "recently played" list of songs from iTunes to my web server, but it's abandonware, & doesn't seem to work with ssh, at least on my new hosting service (Nearly Free Speech)

I can still generate the file with Kung-Tunes, and I can synchronize the folder with Transmit, but is there a way that I can automate Transmit or another program like it to automatically log in via ssh & transfer the file whenever it is written every 3-5 minutes?

Running Mac os 10.5.8 on ppc
posted by Devils Rancher to Computers & Internet (12 answers total) 1 user marked this as a favorite
sounds like a job for applescript.
posted by Mad_Carew at 8:33 PM on September 1, 2012

I don't have 10.5.8 (I'm on Mountain Lion), but the following should work:

Open Automator
Select Folder Action as the new type of Automator script
The action you want is called Upload and it is provided by Transmit, fill in the necessary details
Set the folder to be the folder that Kung-Tunes dumpts the html file to

(If you don't have Transmit [you did mention it] you can do this just as well with a bash script and ssh keys. If 10.5.8 doesn't have Automator [not sure when it was introduced], you can do this with cron firing a bash script and ssh keys.)
posted by Brian Puccio at 8:38 PM on September 1, 2012

Or automator. Automator can set up an action on a folder to do many things, including "Run Shell Script." The shell script can do the ssh/transfer and can delete the file in the action folder so that it can do the next thing on the next generated file.

Or, if you're a bash kind of person, you can use the unix utility "rsync" and a cron job that fires every five minutes.

Or if you don't want to sync but just want to copy files, use "scp" in an every five minute cron job.
posted by Mad_Carew at 8:40 PM on September 1, 2012

Response by poster: I wish I were applescript savvy, but alas, I'm a point & click end-user of the lowest sort. I can read manuals, though.

I just tried Automator using the "Get Specified Finder Items" and the "Upload" (Transmit) actions, but it sticks at the "overwrite file?" dialog, and I don't see how to make it run automatically every time the file is modified.

I understand the rudiments of the bash command line & rsync, but have never run or written a shell script in my life.
posted by Devils Rancher at 8:52 PM on September 1, 2012

assuming the file isn't large enough that you wouldn't mind false positives you could just upload it every minute using cron. A cron tutorial. If automatically logging in is an issue you can look into ssh key authentication
posted by mce at 9:47 PM on September 1, 2012

You can use ExpanDrive or another SSHFS system to make your remote SFTP server look like a local disk on your Mac. Then you shouldn't need to do any scripting—just save in the appropriate folder directly.
posted by grouse at 12:13 AM on September 2, 2012 [1 favorite]

This doesn't answer your direction question, but have you considered using something like Dropbox or another cloud storage platform? That's really the most straight-forward way of keeping files in sync, and it sounds like that's the problem you're trying to solve.
posted by deathpanels at 12:36 AM on September 2, 2012

I don't see how to make it run automatically every time the file is modified

I expect you could do this with Folder Actions.
posted by flabdablet at 3:22 AM on September 2, 2012

Response by poster: I'm going to give ExpanDrive a shot in a little while.

I did manage to get Automator to work whenever I added a new file, though updating an existing file doesn't seem to trigger any of the pre-rolled scripts in there, and I still had to okay overwrite manually in Transmit. There's a preference to turn that off globally, which seems dangerous for my other uses.

Is there a good web repository of Folder Actions? They seem like an option, & that's what Automator acts on anyway, I just need one that triggers on file modification.

I don't think I want a chron script going off every set amount of time, as I might go days or weeks without running my web radio station, which is what this is for. It displays either an off the air message, or the currently playing + last five tracks, when it's broadcasting.

Dropbox isn't an option, I don't think, because I need to link to & display the file on my web page. Unless I'm missing something fundamental about Dropbox, it doesn't do standard web-serving.
posted by Devils Rancher at 6:30 AM on September 2, 2012

Best answer: Dropbox has a “Public” folder that does do standard web serving. You can’t change the URL, but you can (for example) put the page in a frame.
posted by migurski at 8:03 AM on September 2, 2012 [2 favorites]

Response by poster: Geez, why did I think they'd eliminated that a while back? I've had a Dropbox account for 3 years. Some times the solution is so easy I cant see it through my ideas of complexity.
posted by Devils Rancher at 10:30 AM on September 2, 2012

lsyncd is what you want if you don't want a dependency on dropbox.
posted by devnull at 1:55 AM on September 3, 2012 [1 favorite]

« Older What is this wonderfully primitive sounding...   |   How does one actually send money to African people... Newer »
This thread is closed to new comments.