Issue with ftp

Hi friends,

in one of the script i am doing ftp from solaris to a windows machine. From there i wll cd to specific directory.

Now, let's say the directory is not there, then the cd command will fail.
So, how i wll get to know here(in the unix box) that the command has failed.

Thanks

ftp does not return an error on exit, it prints return codes while it is running.

List of FTP server return codes - Wikipedia, the free encyclopedia

#!/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

You could also just add

mkdir directory

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.