Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

check FTP Status

Status
Not open for further replies.

solepixel

Programmer
May 30, 2007
111
US
I have a function that is supposed to return "good" or "bad" if FTP credentials are working or not. Problem is:
1. It takes a rather long time and sometimes times out or something, causing it to break my page.
2. If it produces any sort of error, it displays the full error rather than the ones I created.

Code:
function checkFTP($ftp_server, $ftp_user, $ftp_pass){
	if(strstr($ftp_server,"http")){
		$ftp_server = str_replace("[URL unfurl="true"]http://","",$ftp_server);[/URL]
		$ftp_server = str_replace("[URL unfurl="true"]https://","",$ftp_server);[/URL]
	}
	if(strstr($ftp_server,"[URL unfurl="true"]www.")){[/URL]
		$ftp_server = str_replace("[URL unfurl="true"]www.","",$ftp_server);[/URL]
	}
	
	$ftp_conn = ftp_connect($ftp_server) or die('<span class="bad"><strong>Negative</strong> - bad host/domain name</span>');
	
	if(!ftp_login($ftp_conn, $ftp_user, $ftp_pass)){
		echo '<span class="bad"><strong>Negative</strong> - invalid login credentials</span>';
		die();
	} else {
		echo '<span class="good">Affirmative</span>';
	}
	ftp_close($ftp_conn);
}
Is there a better way to do this, especially if I wanted to do like 20 on the same page?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top