Checking the valid paths in the shell script

Hi i am using a shell script for renaming the files and placing in the remote location(FTP) my code is:
cd $1
day=$(date +%d)
for i in `ls -1 BBW*`
do
last=`tail -1 $i`
pat=`expr "$last" : '.*(\(.*\)).'`
pat=`echo $pat | sed 's/ //'`
pat=$pat$day
mv $i $pat
rm -f $day
done
#!/usr/bin/sh
ftp -v -n "$2" << cmd
user "$3" "$4"
cd $5
mput *

bye
cmd
pwd
exit

and parameters(arguments) are
$1(FilePath)=/data/customer/Personal/na
$2(IPAddress)=123.369.45.65
$3(Username)=xvxvxvx
$4(pASSWORD)=*****
$5(FilePath)=/data/man/sub

this is giving output

Requriment:

And also i want to check the file paths are valid paths($1,$5) please tell how to change the script for checking the valid paths.if the filepaths are find invalid i want to stop the executing the script.please give some modification code to check the file paths are valid.

i have posted a wrong answer, pls ignore my message.

is it the $pat that represents the path. if you want to check if this is a valid path use

if [ ! -d $pat ]
then
exit $err
fi

hi

Thanks for your advise. I want move the files in to remote location(FTP) having a particular filepath. i want check the filepath in the remote location(FTP) is valid. if the path is invalid i want to stop execution of script

code:

#!/usr/bin/sh
ftp -v -n "$2" << cmd
user "$3" "$4"
cd $5
mput *_*
bye

$5 (filepath):data/sas/brg/per

i want to check the file path in remote location(FTP) is valid or invalid.if it is invalid stop the execution of script.please give some advise for my requirement