#!/bin/ksh
echo "
open nodename
user username password
cd /somewhere
put myfile
bye
" | ftp -n 2&>1 > ftp.log
egrep '(^4|^5)' ftp.log # check for a return code like 5xx or 4xx
if [ $? -eq 0 ] ; then
echo 'okay'
else
echo 'ftp failed'
fi
to the beginning of the ftp input.
If it does not exist it will be created. If it does exist you will only get a message saying that it already exists, and your ftp script will continue.
There are also some FTP clients which provide options to check whether a directory exists or not before starting a transfer, and create the folder structure if needed.