Detect reason for ftp error

When using php’s ftp methods, is there any way to detect the reason for a function’s failure?
Specifically thinking about get and put, how can we differentiate between a timeout (in which case we try again) and the connection has expired (in which case we need to reconnect and re-try).
Even if the connect has expired, the resource still appears to be active (unless we explicitly close it).

I tried using error_get_last() to capture the text of the warning:

$h = ftp_connect("");
$l = ftp_login($h, "myusername", "mypassword"); 
sleep(500);//get the connection to expire
$r = ftp_get($h,"localfile.txt,"remotefile.txt",FTP_ASCII );
	echo "reason for error : ";

, but this output just confirms the connection handle is unchanged (resource(2) of type (FTP Buffer)), and gives some meaningless warning message (“ftp_get(): 0.000 seconds (measured here), 7.26 Mbytes per second”).

Is there any better way?