Picture Uploading Voodoo written 5 years ago
Description
This guide shows you how to automate uploading / resizing of pictures to an online ftp site.
Pre-Requisites
Imagemagick provides the command line tools required to resize images. You’ll need to install this, and make sure it’s in your
pathenvironment variable. Not necessary unless you want to resize your images.Windows is required for this guide, but I’m sure you unix guys can use this as a basis for a simple shell script. I wonder if you could use OS X Automator to do something similar? hmm.
The Plan
We’re going to create a simple script that builds a list of images to upload, then uses a command line ftp client to upload the images to the server. We’ll then use the task scheduler to automate this task, and have it occur every day, or as often as we’d like
copyImages.cmd
This will be our main file, and will resize and upload the images. Copy the following into a text file, and save as copyImages.cmd, editing the various parts where necessary.
SET IMAGEDRIVE=E:
SET IMAGEDIR=E:\Phone\
SET HOST=www.sennir.co.uk
SET USER=username
SET PASS=password
A few variables, insert your host, username and password where specified.
%IMAGEDRIVE%
cd %IMAGEDIR%
REM Build the list of files in the firectory
dir /b *.jpg > copyImages.local
CD Into the folder containing the required images, and build a list of the images in the folder, copyImages.local.
REM Now Build the ftp commands
echo open %HOST% > copyImages.ftp
echo %USER%>> copyImages.ftp
echo %PASS%>> copyImages.ftp
REM turn prompting off..
echo prompt >> copyImages.ftp
REM turn to binary
echo binary >> copyImages.ftp
echo cd ~/public_html/images/phone >> copyImages.ftp
Here we output the necessary commands to deliver to the ftp client. This is outputted to copyImages.ftp.
REM Build the list of files that needs to be uploaded
for /F %%i in (copyImages.local) do if not exist .\resize\%%i (
convert %%i -resize 160x120 .\resize\%%i
echo put .\resize\%%i>>copyImages.ftp
)
This section executes a for loop over the contents of the file listing, and for each filename in the file it checks to see if we have already resized it. If we haven’t resized it (the file doesn’t exist) we resize it, and append the ftp command to upload it to the ftp command file.
echo close>> copyImages.ftp
echo quit>> copyImages.ftp
REM Do the ftping
ftp -s:copyImages.ftp
Here we output the ftp commands to close the connection, then we set the ftp client going, using the ftp commands file we created.
You can download copyImages.cmd here*.
Automation
Once you’ve got your script set up and working correctly, you should be able to just double click this file to run the script, and upload your images.
To automate the process, simply navigate to Control Panel > Scheduled Tasks > new Task. Here you can set up the scheduler to run your task when and as often as you like :)
Disclaimer
Don’t blame me if all your photos turn into small pictures of your pet gerbil. This script works fine for me, and I trust it not to do nasty thing with my piccies. Everything presented here is given AS-IS and comes with no warranty whatsoever.. blah blah..
* Windows may complain at you for trying to download a malicious file. You’ll need to assure it otherwise :)
There are no responses to this entry
Do you want to say something? Use the form below to add your thoughts.
Note if you submit your comments, they'll appear here! yes, right below this. Try and make them relevant eh?
Leave a reply
Notes on leaving replies:
Anything you type here will be visible to the world! type wisely.
Want to make your comment look pretty? Use markdown syntax for advanced formatting and link options.
Got Gravatar? Stick your email address in!
By using this, you agree to the Privacy Policy.
Site navigation