Picture Uploading Voodoo written 12 years ago

A porthole into the world of rob!


This guide shows you how to automate uploading / resizing of pictures to an online ftp site.


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


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 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.

    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*.


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 :)


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 :)

← previous entry | next entry → Thu 7th Jul 2005 - 15:12 | no comments | tagged with

 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

Name: displayed next to your comment
Email: will not be displayed
URL: to link back to your site
Comments: Markdown syntax allowed

Notes on leaving replies: