FTP upload images with Hazel and Bash

As an addendum to this post and this post here’s a recent addition I made to my workflow which allows me to share or embed image files quickly.

I already have a Hazel rule that resizes any image placed in a certain directory. For a while I was just using the Dropbox public link for these images to embed them in posts. This isn’t ideal, however, as I can’t really rely on these links always being the same. I have my own hosting, so it makes sense to upload the files via FTP and then link to them there. The problem is that there wasn’t a really nice workflow to FTP upload files and get their URLs, especially on an iOS device.

I searched around and found this post by Dan Sturm which was pretty much what I was looking for. I needed to rewrite it a bit in order to fit my particular use case, and whilst I was at it I decided to also make sure that all the uploaded files had dashes instead of spaces. Here’s what I came up with (and thanks to Dan for doing all the hard work…):

Hazel rule to upload images

Hazel Rule Hazel Rule

Bash script to upload:

# FTP login details
# Get the base name of the file and if necessary replace spaces with dashes
 JNAME=${JNAME// /-}  

# FTP login and upload
 ftp -inv $HOST \<\< EOF
 user $USER $PASS
 put “$1” “/public\_html/$JNAME”
# Copy the address of the image to a log file
echo “http://yourdomain.com/$JNAME” \>\> UPLOADS\_LOG\_FILE.txt