Shell script error catching

Hi Guys,
I am working on a script that will use curl and have a person enter a server, username and password. Then, I check this to make sure that this works (my error catch). The problem is, the way I have written it, once I run a shell script command, Applescript waits until it is finished before moving on in the code. Therefore, if the server name is wrong, I can’t put an error or “repeat while” loop into it because the shell script throws its own error and then quits. Ignore the rest of the if function, they just are there to help me test the script.



set the_button to button returned of (display dialog "Welcome to the script, would you like to use the FTP and Mail function?" buttons {"Yes", "No"} default button "Yes")
if the_button is "Yes" then
	set n to 1
	set found to false
	repeat while not found and n ≤ 3
		
		display dialog "Please enter the server:" default answer ""
		set theServer to text returned of result
		
		display dialog "Please enter your username:" default answer ""
		set userName to text returned of result
		
		display dialog "Please enter your password:" default answer ""
		set thePass to text returned of result
		
		--Test the FTP site
		set testingSite to "curl ftp://" & theServer & " --user " & userName & ":" & thePass
		set UploadResponse to do shell script testingSite
		
		--how do you make this part delay only a certain time and continue past the shell script.  Basically, it will get hung here and there needs to be error catching here.
		
		set returnResult to the result as text
		if returnResult contains "drw" then
			set found to true
		else
			set n to n + 1
			display dialog "Failed"
		end if
	end repeat
	
	
	
	
--This is just to help me check the code.	
else
	display dialog "Finished"
	
end if


Thank you for your help.